js 獲取iframe頁面元素
CreationTime--2018年8月16日18點00分
Author:Marydon
<!-- chart圖表 --> <iframe id="myframe" src="<c:url value="/base/server/report/report.do?REPORT_ID=${param.REPORT_ID}"/>" height="100%" width="100%"></iframe>
1.通過父頁面操縱子頁面
獲取iframe頁面中的元素
操作 | javascript | jQuery |
方式一 | document.getElementById("myframe").contentWindow.document.getElementById("V_ORGID").value = 111; | $("#myframe").contents().find("#V_ORGID").val('111'); |
方式二 | document.frames["myframe"].document.getElementById("V_ORGID").value = 111; | $("#V_ORGID",document.frames("myframe").document).val('111'); |
調用iframe頁面中的方法
操作 | javascript | jQuery |
方式一 | document.getElementById("myframe").contentWindow.test(); | |
方式二 | document.frames["myframe"].test(); |
2.通過子頁面操縱父頁面
獲取iframe頁面中的元素
操作 | javascript | jQuery |
方式一 | window.parent.document.getElementById("ORGID").value = 111; | $("#ORGID",parent.document).val('111'); |
調用iframe頁面中的方法
操作 | javascript | jQuery |
方式一 | window.parent.test2(); |
updateTime--2018年8月23日19點14分
3.通過子頁面操縱父頁面中的其它iframe頁面
前提:iframe必須設置了id。
獲取iframe頁面中的元素
window.frames['id'].document.getElementById();
調用iframe頁面中的方法
window.frames['id'].test();