获取父窗口元素或者获取iframe中的元素(相同域名下)

jquery方法

在父窗口中获取iframe中的元素

//方法1
$("#iframe的ID").contents().find("iframe中的元素");
//实例:
$("#ifr").contents().find("#someid");
//方法2
$("#iframe中的控件ID",document.frames("frame的name").document);
//实例
$("#someid",document.frames("ifr").document);

在iframe中获取父窗口的元素

//方法
$('#父窗口中的元素ID', parent.document); //实例 $('#someid', parent.document);

js方法

在父窗口中获取iframe中的元素

//方法
window.frames["iframe的name值"].document.getElementById("iframe中控件的ID");
//实例
window.frames["ifr"].document.getElementById("someid");

在iframe中获取父窗口的元素

//方法
window.parent.document.getElementById("父窗口的元素ID");
//实例
window.parent.document.getElementById("someid");

欢迎补充!

原文地址:https://www.cnblogs.com/sysg/p/6549096.html