在IFrame中查找IFRAME中的元素的方式

下面是内部iframe找外部mainFrame的情况
 var websiteSearchButton = window.parent.parent.document.getElementById('mainFrame')
     .contentWindow.document.getElementById("webresource-search-button"); 

iframe中
1、子页面找符页面中的元素
$(window.parent.document).find(id);
2、父页面--->子页面中的
$(id).contents().find(元素id).find(元素id);
3、子页面--->爷爷界别的页面
$(window.top.document).find(id);


例子:
var body2 = jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body").html();
console.log(body2);

1、window.top.document.getElementById("eWebEditor2")     :表示在一个iframe中找最顶层中的document,然后在找最外层的document中的eWebEditor2的这个元素(上例子表示的是一个iframe),

2、jQuery(window.top.document.getElementById("eWebEditor2"))    表示把eWebEditor2这个iframe转成jQuery对象

3、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0)   表示取到第一个元素

4、.contents().find("#eWebEditor")    表示取eWebEditor2这个iframe中eWebEditor这个元素(这里这个元素表示的又是一个iframe)

5、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents()    表示eWebEditor这个iframe中的内容

6、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body")   表示取到eWebEditor这个内容中的body元素

7、最终 jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body").html();    表示body中的内容


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值