父窗口中的jQuery选择元素

编程入门 行业动态 更新时间:2024-10-27 23:16:39
本文介绍了父窗口中的jQuery选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法使用jQuery在父窗口中选择一个DIV?

Is there a way to select a DIV in the parent window using jQuery?

例如:

主页包含这个,

<div id="testdiv"></div>

弹出页面有一个带有一些选项的表单和一个应用"按钮.当用户点击应用时,它会影响主页上的样式属性.

Popup page has a form with some options and an 'Apply' button. When the user clicks apply it affects the style attribute on the main page.

一些符合逻辑的东西,

parent.$("#testdiv").attr("style", content from form);

推荐答案

使用上下文参数

$("#testdiv",parent.document)

但如果你真的使用弹窗,你需要访问 opener 而不是 parent

But if you really use a popup, you need to access opener instead of parent

$("#testdiv",opener.document)

更多推荐

父窗口中的jQuery选择元素

本文发布于:2023-10-31 02:01:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544658.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   窗口中   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!