gpt4 book ai didi

javascript - 在这种情况下检测 window.load 的有效方法

转载 作者:行者123 更新时间:2023-11-28 09:55:32 24 4
gpt4 key购买 nike

我的要求是,我必须在所有页面脚本执行完成后执行一个脚本。我正在使用下面的代码来执行相同的操作

$(window).load(function ()
{
var j = setTimeout (function ()
{
alert("All page scripts have been executed and DOM is ready.");
// And here the script will work
to update the DOM changes made by the pagescripts.
},100); // Here execution time cant be less than 100 all the time, right?
});

但问题是,在上面的例子中我使用了时间100。但有时页面加载时间为101毫秒。在这种情况下,脚本无法更新更改。让我们看一个例子

有一个页面脚本,当 DOM 准备好时,它将向 DOM 添加图像。如果我使用

$(document).ready()   

脚本无法检测图像,因为图像尚未添加到 DOM。

如果您需要对问题进行更多说明,请告诉我。

最佳答案

如果问题出在图像上,您需要预加载它们。
尝试使用this extension

关于javascript - 在这种情况下检测 window.load 的有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10107229/

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