gpt4 book ai didi

javascript - 使 document.ready 考虑外部 iframe 中的元素

转载 作者:行者123 更新时间:2023-11-28 02:16:51 25 4
gpt4 key购买 nike

我发现自己所处的位置如下。我有一个 jQuery 插件,需要嵌套在 document.ready 函数中。该插件对页面元素应用一些样式。受此插件影响的元素之一包含 iframe。这个 iframe 不是来 self 的网站。问题是 document.ready 没有考虑 iframe 的内容,当它加载时,它的高度发生变化,但在此之前已经应用了 jQuery 插件,因此页面的布局被搞砸了.

我尝试了以下方法来确保仅当文档准备好且 iframe 也准备好时才调用插件:

$(document).ready(function() {
$('#frameId').ready(function() {
//plugin code
});
});

但这不起作用,我正在寻找另一种解决方案。

最佳答案

只有文档才有 ready() 事件,对于 iFrame 来说,它将是 onload :

$(document).ready(function() {
$('#frameId').on('load', function() {
//plugin code
});
});

但是为什么你的插件需要访问 iFrame ?

关于javascript - 使 document.ready 考虑外部 iframe 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16268669/

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