码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-25 18:23:30      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

下面是内部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中的内容在IFrame中查找IFRAME中的元素的方式

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

标签:

原文地址:http://www.cnblogs.com/ywyhero/p/5527904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!