gpt4 book ai didi

javascript - 无法从 iframe 内部将边框应用于 iframe

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:42 25 4
gpt4 key购买 nike

我在 iFrame 中。我控制内部/外部/父/子内容,它们都在同一个域中。没有安全异常(exception)。

如果我在 Chrome 控制台中运行它,边框会完全按照我想要的方式应用:

$("[name='PPDGFrame']").css("border", "2px solid #334930");

然而,当我以编程方式做完全相同的事情时,它永远行不通:

$(document).ready(function() {
$("[name='PPDGFrame'], window.parent.document").css("border", "2px solid #334930");
});

甚至这样:

$(document).ready(function() {
setTimeout(function(){
$("[name='PPDGFrame'], window.parent.document").css("border", "2px solid #334930");
}, 3000);
});

在代码中执行时,不存在任何错误,并且在控制台中我清楚地获得了对象的句柄。还是没有边界。

我做错了什么?

最佳答案

window.parent.document 指定为 context for the selector要在其中搜索,它应该作为字符串后的单独参数传递。

$("[name='PPDGFrame']", window.parent.document)
// ^^

目前,在选择器中,, 被理解为 multiple selectorwindow.parent.document 作为 element selectorclass selectors搜索:

<window class="parent document">

这是一个有效的选择器,这就是您没有收到任何错误的原因。它只是不匹配任何内容,因为您的文档中可能没有这样的元素。

关于javascript - 无法从 iframe 内部将边框应用于 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29628840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com