在iframe子页面获取父页面元素
代码如下:
$('#objId', parent.document)
// 搞定...
在父页面 获取iframe子页面的元素
代码如下:
$("#objid",document.frames('iframename').document)
$(document.getElementById('iframeId').contentWindow.document.body).html()
显示iframe中body元素的内容。
$("#testId", document.frames("iframename").document).html()
根据iframename取得其中ID为"testId"元素
$(window.frames["iframeName"].document).find("#testId").html()
用JS或jQuery访问页面内的iframe,兼容IE/FF
注意:框架内的页面是不能跨域的!
html:<div id="div1">
<iframe id="iframe1" src="frame1.html"></iframe>
<iframe id="iframe2" src="frame2.html"></iframe>
</div>
frame1.html js:
//#btn为frame1.html的按钮
$("#btn").click(function(){
var str = s()
//#myh3为frame2.html的h3标签id
$("#iframe2", window.parent.document).contents().find("#myh3").text(str)
})