顺序: window--document--body--元素
1. 子iframe中调用父中方法 :xxx()
window.parent.xxx() 或者 parent.xxx()
2. 父调用子iframe 方法xxx()
<iframe src="index2.html" scrolling="no" name="iframeName" id="ifrid"></iframe>
window.iframeName.xxx();
或者
var ifr = document.getElementById("ifrid");
ifr.contentWindow.xxx();
小结: 调用方法需要用window
3.子iframe得到父的元素<span id="spantext">hello</span>
js: window.parent.document.getElementById("spantext")
jquery:$("#spantext",window.parent.document)
4. 父获取子iframe元素 三种方式
方式1:
var ifm = document.getElementById("ifrid");
ifm.contentWindow.document.getElementById("iframetext")方式2:ifr 是iframe的name值
window.ifr.document.getElementById("iframetext");
方式3:ifrid是iframe 的id值
window.frames["ifrid"].contentWindow.document.getElementById("iframetext");
jquery方式 :$("#iframetext",上面三种方式的到document(
ifm.contentWindow.document
))
总结:获取iframe,然后window-document