JS操作iframe元素
- 父页面操作子页面
//获取iframe元素
var oIframe = document.getElementById('iframe1');
oIframe.contentWindow.document.body.style.color = 'red';
- 子页面操作父页面;
var oDiv = window.parent.document.body.children[0];
oDiv.style.color = 'red';
JQuery操作iframe
- 在父页面中获取iframe中的元素
$(this).contents().find("#suggestBox")
$("#mainiframe").contents().find("someID").html()
$("#objid",document.frames('iframename').document)
$(window.frames["iframe1"].document).find("#id")
$(window.frames["iframe1"].document).find(”input[@type='radio']“).attr(”checked”,”true”);
- 在子页面(iframe)中查找父页面元素
$('#id', window.parent.document)
$('#objId', parent.document);
$(window.parent.document).find(”input[@type='radio']“).attr(”checked”,”true”);
// 调用父页面属性和方法
parent.method
parent.value