jquery如何获取iframe中的元素

jquery如何获取iframe中的元素,第1张

只有 当iframe里的页面和当前页面 处在同一个域下时才可以

$($('#A')prop('contentWindow')document)find("#B");

这样你试试

页面A包含B和C两个iframe

则B与C要相互访问都可以使用parent访问A,通过A这个桥梁来访问B和C

A页面

function getC(){

return documentgetElementById("C");

}

function getB(){

return documentgetElementById("B");

}

<iframe id="B" allowtransparency="true" scrolling="no" frameborder="0" src="/bjsp"></iframe>

<iframe id="C" allowtransparency="true" scrolling="no" frameborder="0" src="/cjsp"></iframe>

B页面

function getmyc(){

var c=parentgetC()mycinnerHtml;

alert(c);

}

<div id="myb">bbbb</div>

C页面

<div id="myc">cccc</div>

//1、格式:

windowframes["iframe的name值"]documenttitle;

//实例

windowframes["ifm"]documenttitle;

//2、格式:

var obj=documentgetElementById("iframe的name")contentWindow;

var ifmObj=objdocumenttitle;

//实例:

var obj=documentgetElementById("ifm")contentWindow;

var ifmObj=objdocumenttitle;

//3、格式:

windowparentdocumentgetElementById("父窗口的元素ID")title;

//实例:

windowparentdocumentgetElementById("ifm")title;

//jquery在父窗口中获取iframe中的元素

//1、格式:

$("#iframe的ID")contents()attr("title");//jquery 方法1

//实例:

$("#ifm")contents()attr("title");//jquery 方法1

//2、格式:

$(selector, windowtopdocument);; //jquery 方法2

//实例:

$(document, windowtopdocument)attr("title");//jquery 方法2

//类似的方法

$(selector, windowtopdocument); 

$(selector, windowopenerdocument); 

$(selector, windowtopframes[0]document);

以上就是关于jquery如何获取iframe中的元素全部的内容,包括:jquery如何获取iframe中的元素、jquery查找iframe中的元素、jquery在父页面获取iframe子页面的title,怎么获取等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9413788.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存