jquery操做包含iframe的页面中元素的几种方法:html
// //在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")
注意:因为安全问题,协议规定框架内的页面是不能跨域的!jquery