父页面寻找子页面元素:
window.frames["iframeName"].document.getElementsByClassName('div')[0]
$(document.getElementById("iframeId").contentWindow.document).find(".div")
$( window.frames["iframeName"].document).find(".div")
$("#iframeId").contents().find(".div")
iframeName为iframe的name属性值
父页面调用子页面方法:
iframeName.window.chlidFunctionName()
子页面寻找父页面元素:
$(window.parent.document).find(".divParent")
window.parent.document.getElementsByClassName("divParent")[0]
$(". divParent",parent.document)
子页面调用父页面方法:
parent.parentFunctionName()
本文介绍了父页面与子页面(如iframe)之间的元素查找及方法调用技巧,包括父页面如何查找及调用子页面元素与方法,以及相反方向的操作。
804

被折叠的 条评论
为什么被折叠?



