取父窗口的元素方法:$(selector, window.parent.document)
那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document)
类似的,取其它窗口的方法大同小异
$(selector, window.top.document)
$(selector, window.opener.document)
$(selector, window.top.frames[0].document)
希望对你能有帮助
取父窗口的元素方法:
$(selector, window.parent.document)
那么你取父窗口的父窗口的元素就可以用:
$(selector, window.parent.parent.document)
类似的,取其它窗口的方法大同小异,
$(selector, window.top.document)
$(selector, window.opener.document)
$(selector, window.top.frames[0].document)
js:
父窗口:
1、<input type="text" name="currentProjectIDForDetail" id="currentProjectIDForDetail"
disabled
2、<input type="button"
onclick="window.open('showDetails.html','','toolsbar=no,menubar=no,resizable=yes,scrollb
ars=yes')" value="查看已有明细" id="showDetail" />
子窗口:
curproject = window.opener.document.getElementById("currentProjectIDForDetail").value
jQuery:
父窗口:
<input type="text" name="aa" id="aa" />
<input type="button"
onclick="window.open('son.html','','toolsbar=no,menubar=no,resizable=yes,scrollbars=yes')
" value="send" />
子窗口:
<script>
$(function () {
temp=$("#aa",window.opener.document).val()
$("#bb").html(temp)
})
</script>
</head>
<body>
<div id="bb"></div>
JS子窗口调用父窗口的方法:
框架(iframe)形式,这时用到是window.parent, window.parent能获取一个框架的父窗口或父框架。顶层窗口的parent引用的是它本身。可以用这一点特性来判断这个窗口是否是顶层窗口。详情如下:
1、1.html代表的是父窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
<title>父页面</title>
</head>
<body>
<form name="form1" id="form1">
<input type="text" name="username" id="username" />
</form>
<iframe src="2.html" width="100%">
</body>
</html
2、2.html代表的子窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
<title>子页面</title>
<script type="text/javascript">
function changeValue(val){
var _parentWin = window.parent
_parentWin.form1.username.value = val
}
</script>
</head>
<body>
<input type="file" name="filename" onchange="changeValue(this.value)" />
</body>
</html>
这时在子窗口(iframe窗口)所做的改变,会改变父窗口中username的值。