工作中经常会用到,记录一下,免得总是到处找。
一、在父窗口中获取iframe中的元素
JS:
1.window.frames["iframe的name值"].document.getElementById("iframe中控件的ID")
2.var obj=document.getElementById("iframe的name").contentWindow;
var ifmObj=obj.document.getElementById("iframe中控件的ID");
jquery:
1.$("#iframe中的控件ID",document.frames("frame的name").document)
2.$("#iframe的ID").contents().find("#iframe中的控件ID")
二、iframe中获取父窗口的元素
JS
1.window.parent.document.getElementById("父窗口的元素ID")
2.$("#iframe中的控件ID",document.frames("frame的name").document
JQUERY:
1.$('#父窗口中的元素ID', parent.document)