您的位置:首页 > Web前端 > JQuery

沫沫金:实践使用的jQuery获取框架内容的方法

2012-06-19 14:20 495 查看

沫沫金亲自验证,支持IE6

沫沫金分享利用Jquery取得iframe中元素的几种方法 :

document.getElementById方式:Js代码

$(document.getElementById('iframeId').contentWindow.document.body).htm()

$(document.getElementById('iframeId').contentWindow.document.body).htm()

显示iframe中body元素的内容。

jQuery双参数法:Js代码

$("#testId", document.frames("iframename").document).html();

$("#testId", document.frames("iframename").document).html();

根据iframename取得其中ID为"testId"元素

jQuery的find方法获取法:Js代码

$(window.frames["iframeName"].document).find("#testId").html()

$(window.frames["iframeName"].document).find("#testId").html()






在IFRAME里取得父窗口的某个元素的值,使用jQuery

只好用DOM方法与jquery方法结合的方式实现了,dom很强大的

1.在父窗口中操作 选中IFRAME中的所有单选钮

$(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

2.在IFRAME中操作 选中父窗口中的所有单选钮

$(window.parent.document).find("input[@type='radio']").attr("checked","true");

iframe框架的:<iframe src=\'#\'" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: