iframe 父级子级相互获取元素的方法

18 篇文章 0 订阅

1)在iframe中查找父页面元素的方法:
$('#id', window.parent.document)

2)在iframe中调用父页面中定义的方法和变量:
parent.method

parent.value




在iframe子页面获取父页面元素

 代码如下:

$.('#objld', parent.document); 
在父页面获取iframe子页面的元素

 代码如下:

$("#objid", document.iframes('iframe').document) 

 代码如下:

$(document.getElementById('iframeId').contentWindow.document.body).html() $(document.getElementById('iframeId').contentWindow.document.body).html()


显示iframe中body元素的内容

 代码如下:

$("#testId", document.frames("iframename").document).html()

 

(1)父页面获取iframe中的元素值:

Js代码  
1.//根据iframe的id获取对象   
2.var i1 = window.frames['iframeId'];   
3.//var iframe =window.frames[0];也可以   
4.//获取iframe中的元素值   
5.var val=i1.document.getElementById("t1").value  
//根据iframe的id获取对象
var i1 = window.frames['iframeId'];
//var iframe =window.frames[0];也可以
//获取iframe中的元素值
var val=i1.document.getElementById("t1").value

(2)在iframe中获取父页面中的元素值:

Js代码  
1.var val = parent.document.getElementById("txt1");   
var val = parent.document.getElementById("txt1");

(3)a包含2个iframe分别为b,c,现在从b中获取c中的元素的值:

Js代码  
1.var i1 = parent.window.frames['iframeId'];   
2.var val = i1.document.getElementById("text1").value;  
var i1 = parent.window.frames['iframeId'];
var val = i1.document.getElementById("text1").value;


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值