JQUERY 问题,为什么我不能在本地托管的 iframe 内进行更改?

发布于 2024-08-29 12:56:29 字数 677 浏览 2 评论 0原文

在页面上给出以下内容:

<iframe frameborder="0" allowtransparency="true" tabindex="0" src="" title="Rich text editor" style="width: 100%; height: 100%;" id="hi-world">
<p><span class="tipoff" title="System tooltip for search engines">Download now</span></p><p>adasdads</p><p>a</p><p><span class="tipoff" title="System tooltip for search engines">Download n1111ow</span></p>
</iframe>

以下有效:

$('#hi-world').css("width","10px");

但我想做的是更改 iFrame 中的段落,但这不起作用:

$('#hi-world').find('p').css("background","red");

Give the following on a page:

<iframe frameborder="0" allowtransparency="true" tabindex="0" src="" title="Rich text editor" style="width: 100%; height: 100%;" id="hi-world">
<p><span class="tipoff" title="System tooltip for search engines">Download now</span></p><p>adasdads</p><p>a</p><p><span class="tipoff" title="System tooltip for search engines">Download n1111ow</span></p>
</iframe>

The following works:

$('#hi-world').css("width","10px");

But what I want to do is change the paragraphs in the iFrame, and this does not work:

$('#hi-world').find('p').css("background","red");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫言歌 2024-09-05 12:56:29

好吧,刚刚想通了:

$('#hi-world').contents().find('p').css("background","red");

ok just figured it out:

$('#hi-world').contents().find('p').css("background","red");
江挽川 2024-09-05 12:56:29

第一个是更改 iframe 元素的 css。要执行第二个操作,您必须访问 contentDocument。如前所述,在 jQuery 中,您可以使用 contents 来实现此目的。

The first is changing the css of the iframe element. To do the second, you have to access the contentDocument. As noted, in jQuery you can use contents for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文