在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中的內容 在IFrame中查找IFRAME中的元素的方式


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 js獲取iframe中的元素 selenium 中在 iframe 內的元素定位 Js/Jquery獲取iframe中的元素 Jq如何獲取並操作iframe中的元素? java selenium (十四) 處理Iframe 中的元素 Jquery如何獲得