
a>window.parent.document这个是获取父页面document中的对象;
b>如果要获取父页面js中的方法:window.parent.xxxx();xxxx()为方法;
2.在父页面中获取iframe子页面中的元素:
a>
var child = document.getElementByIdx_x("mainFrame").contentWindow//mainFrame这个id是父页面iframe的id
child.document//获取子页面中的document对象;
这样的代码就需要用到封包了for(var i...){
(function(j){
...
})(i)
}
这样在循环的时候他们得到的值就是不一样的
写个demo给你,在点击第一个iframe上的按钮时将其文本框中的值写到第二个iframe里的文本框中。
main.html
<!doctype html><html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<iframe name='one' src="iframe.html"></iframe>
<iframe name='two' src="iframe.html"></iframe>
</body>
</html>
iframe.html
<!doctype html><html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function send()
{
var text=document.getElementById('text').value//获取当前iframe中的文本值
var two=parent.frames['two']//获取第二个iframe对象
two.document.getElementById('text').value=text//将第二个iframe对象中的文本值设为当前iframe中的文本值
}
</script>
<body>
<input type="text" id="text" />
<input type="button" value="send" id="btn" onclick="send()" />
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)