標籤:style ext color get 使用 strong
<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: