jQuery在父窗口中选择元素
有没有办法使用jQuery在父窗口中选择一个DIV 例如: 主页上有这个,jQuery在父窗口中选择元素,jquery,jquery-selectors,popup,parent,Jquery,Jquery Selectors,Popup,Parent,有没有办法使用jQuery在父窗口中选择一个DIV 例如: 主页上有这个, <div id="testdiv"></div> 使用上下文参数 $("#testdiv",parent.document) 但如果您真的使用弹出窗口,则需要访问opener而不是父窗口 我寻找解决这个问题的办法,看到了这一页。我实施了上述解决方案: $("#testdiv",opener.document) //doesn't work window.opener.$("#testdiv"
<div id="testdiv"></div>
使用上下文参数
$("#testdiv",parent.document)
但如果您真的使用弹出窗口,则需要访问opener而不是父窗口
我寻找解决这个问题的办法,看到了这一页。我实施了上述解决方案:
$("#testdiv",opener.document) //doesn't work
window.opener.$("#testdiv") //This works.
但它不起作用。也许它在以前的jQuery版本中确实有效,但现在似乎不起作用
我在另一个stackoverflow页面上找到了此工作解决方案:
从中我得到了这个有效的解决方案:
$("#testdiv",opener.document) //doesn't work
window.opener.$("#testdiv") //This works.
为什么不能两者都确定呢
if(opener.document){
$("#testdiv",opener.document).doStuff();
}else{
$("#testdiv",window.opener).doStuff();
}
你也可以用
parent.jQuerytestdiv.attrstyle,表单中的内容 我遇到了同样的问题,但如上所述,公认的解决方案对我不起作用 如果您在框架或iframe元素中,另一种解决方案是使用
window.parent.$('#testdiv');
window.opener指的是名为window.open的窗口。。。打开从中调用它的窗口
window.parent是指框架或iframe元素中窗口的父级
真棒的朋友@莫勒医生太自信了!。。或者说它在2011年起作用了。对于这个答案的解决方案,弹出窗口是否需要已经加载jQuery?今天学习到的新事物的可能副本,谢谢:如果iframe在另一个域中呢?如何关闭它?