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

contentwindow 和contentdocument dom对象和jquery对象

2013-11-11 17:05 387 查看
父页面调用iframe里的js函数

document.getElementById('iframedemo').contentWindow.demofunction(); //与下边一句等价

window.frames['iframedemo'].contentWindow.demofunction();

其中iframedemo是iframe的id,demofunction是iframe里的js函数名

父页面调用iframe里的dom元素

document.getElementById('iframedemo').contentDocument.getElementById("INPUT_Text").value; //与下边一句等价

window.frames['iframedemo'].contentDocument.getElementById("INPUT_Text").value;

其中iframedemo是iframe的id

注意事项:

contentwindow兼容各个浏览器,可取得子窗口的window对象

contentDocument firefox支持 ie8以上的支持

以上说的是父页直接调用父页面iframe里的dom或者是js函数,如果在子页面要调用父页面的js函数或者dom对象,

原理类似:

1 取得父页面的dom对象

var frameJqObj=$("[src='"+src+"']", window.parent.document);//window.parent.document父级窗体的document对象,jquery对象

var frameDomObj=frameJqObj.get(0);//get(num)返回的是个html对象,这个是dom对象

2 父页面调用iframe里的js函数

frameDomObj.contentWindow.demofunction();contentWindow属性是指指定的frame或者iframe所在的window对象

dom对象和jquery对象的转换
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: