JQuery

1、从父页面中获取iframe页面中的元素:

方法1:$(window.frames["父页面中iframe的id属性值"].document).find("#iframe中的控件ID");​​

方法2:$("#iframe的ID").contents().find("#iframe中的控件ID");

方法3:$("#iframe中的控件ID",document.frames("frame的name").document);

2、从iframe中获取父页面中的元素:​​​​​​​

方法1:$(window.parent.document).find("父页面中元素的id属性值");

方法2:$('#父窗口中的元素ID', parent.document);

​​​​​​​

JS

1、从父页面中获取iframe页面中的元素:

方法1:window.frames["iframe的name值"].document.getElementById("iframe中控件的ID");

方法2:var obj=document.getElementById("iframe的name").contentWindow;

var ifmObj=obj.document.getElementById("iframe中控件的ID");

2、从iframe中获取父页面中的元素:

window.parent.document.getElementById("父窗口的元素ID");

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐