DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> js中top/parent/frame概述及案例應用
js中top/parent/frame概述及案例應用
編輯:JavaScript基礎知識     
引用方法top
該變量永遠指分割窗口最高層次的浏覽器窗口。如果計劃從分割窗口的最高層次開始執行命令,就可以用top變量。

parent
該變量指的是包含當前分割窗口的父窗口。如果在一個窗口內有分割窗口,而在其中一個分割窗口中又包含著分割窗口,則第2層的分割窗口可以用parent變量引用包含它的父分割窗口。
附:Window對象、Parent對象、Frame對象、Document對象和Form對象的階層關系

Windwo對象→Parent對象→Frame對象→Document對象→Form對象,如下:
parent.frame1.document.forms[0].elements[0].value;
在JS中:window.location(window.location.href)和window.top.location(window.top.location.href)是一樣的意思 可以通過top來調用任何一個frame,因為top指的是最外層的frameset,可以調用它裡面的任何一個子元素frame。如:top.outterFrame1.location和top.innerFrame2.location等。

parent指的是當前窗口(frame)的父窗口(frameset)可以調用它裡面的任何一個子元素frame。如:parent.innerFrame1.location和parent.innerFrame2.location等。
復制代碼 代碼如下:
<html>
<head>
<title>top frame parent示例</title>
<script language="javaScript" type="text/javaScript">
window.location.href="http://www.baidu.com/";
</script>
</head>
<frameset id="outFrameset" rows="150,*,150" cols="*" border="5">
<frame name="frameName1" id="frameId1" src="a.html">
<frameset id="inFrameset" cols="150,*" rows="*">
<frame name="innerFrameName1" id="innerFrameId1" src="a.html">
<frame name="innerFrameName2" id="innerFrameId2" src="a.html">
</frameset>
<frame name="frameName2" id="frameId2" src="a.html">
</frameset>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved