Jquery:怎样让子窗体的div显示在父窗体之上

<1> js或者jQuery訪问页面中的框架iframe. 
注意:框架内的页面是不能跨域的! 如果有两个页面,在同样域下.

如果:父窗体  index.html ,有id 为 subifrm 的iframe

1. 在index.html运行JS直接訪问子窗体中某元素:

document.getElementById('subifrm').contentWindow.document.getElementById('test').style.color='red'  

 

2. 利用jquery 来訪问子窗体

$("#subifrm").contents().find("#test").css('color','red');

==================================================================== 

==================================================================== 

 

<2> 用DOM方法与jquery方法结合的方式实现互动操作 
1.在父窗体中操作 选中IFRAME中的全部单选钮

$(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

2.在IFRAME中操作 选中父窗体中的全部单选钮

$(window.parent.document).find("input[@type='radio']").attr("checked","true");

==================================================================== 

==================================================================== 

<3> 使用jquery操作iframe 

1 页面里有两个ifame

<iframe id="leftiframe"></iframe>   

<iframe id="mainiframe></iframe>  

<iframe id="leftiframe"></iframe>

<iframe id="mainiframe></iframe>

 

leftiframe中jQuery改变mainiframe的src代码:

1

$("#mainframe",parent.document.body).attr("src","")

 

2、 假设内容里面有一个ID为mainiframe的ifame

<iframe id="mainifame"></ifame>   

<iframe id="mainifame"></ifame> 

  

ifame包括一个someID

<div id="someID">you want to get this content</div>   

<div id="someID">you want to get this content</div> 

 

得到someID的内容

$("#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text(); 

$("#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text();  

$("#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text();

 

2 、如上面所看到的
   leftiframe中的jQuery操作mainiframe的内容someID的内容

$("#mainframe",parent.document.body).contents().find("someID").html();或者$("#mainframe",parent.document.body).contents().find("someID").val();  

source:


原文地址:https://www.cnblogs.com/cxchanpin/p/6852070.html