iframe 父子窗口操作

//
//在iframe子页面获取父页面元素
$('#objId', parent.document);
$(window.parent.document).find("#objId");
 
//在父页面获取iframe子页面的元素
$("#objid",document.frames('iframename').document);
$("#objid",window.frames["iframeName"].document);
$("#objid",document.getElementById('iframeId').contentWindow.document);
$(window.frames["iframeName"].document).find("#objid");
$("#iframeId").contents().find("#objid");
 
//例子
//显示iframe中body元素的内容
$(document.getElementById('iframeId').contentWindow.document.body).html();
//例子
//显示iframe中id为testId的元素的内容
$("#testId", document.frames("iframename").document).html();
$(window.frames["iframeName"].document).find("#testId").html()
//例子
//在父窗口中操作,选中IFRAME中的所有单选钮
$(window.frames["iframeName"].document).find("input:radio").attr("checked","true");
//在IFRAME子窗口中操作,选中父窗口中的所有单选钮
$(window.parent.document).find("input:radio").attr("checked","true");
 
//再进一步
//父窗口想获得IFrame中的Iframe,就再加一个frames子级就行了
$(window.frames["iframe1"].frames["iframe2"].document).find("input:radio")


你可能感兴趣的:(iframe 父子窗口操作)