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");
欢迎补充!
本文介绍了使用jQuery及JS在父窗口与iframe间相互获取元素的方法。jQuery方面,提供了两种方式,一是通过.contents().find()组合使用,二是利用frames属性进行选择;而原生JS则分别采用frames和parent属性配合getElementById实现。这些方法适用于不同场景,帮助开发者灵活地进行页面元素交互。
6997

被折叠的 条评论
为什么被折叠?



