jquery子窗口给父窗口元素赋值和获得值,子窗口调取父窗口方法,父窗口调取子窗口方法

1. 子窗口给父窗口元素赋值

<input type="hidden" id="id">


function modifyId(id){
$("#id",window.parent.document).attr("value",id);//子窗口给父窗口元素赋值
}


2. 子窗口获得父窗口的元素值

var id=$("#id",window.parent.document).val();
alert(id);


3.子窗口调取父窗口的方法

parent.test();//test()  是父窗口的方法


4.父窗口调取子窗口的方法

 var x=document.getElementById("idIframe"); 
 var y=(x.contentWindow || x.contentDocument); 
 y.childrenTest();//childrenTest() 是子窗口的方法

猜你喜欢

转载自blog.csdn.net/dream1120757048/article/details/79088137
今日推荐