js 获取iframe页面元素


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();

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM