Javascript/jQuery HasLoaded 或等效项?

发布于 2024-09-02 11:46:10 字数 257 浏览 2 评论 0原文

我知道在 jquery 中可以调用 javascript/jquery onload()/load() 函数,例如图像 (< /代码>)。

但是,如果在 jquery 中,如果我使用 .html(htmlString) 在 dom 加载后插入图像,我如何添加一个侦听器来处理图像 onload 事件?是否有一个属性我可以检查以查看各种图像以及它们是否已加载?

I know in jquery it is possible to call the javascript/jquery onload()/load() functions on, for example an image (<img>).

However, if in jquery if i use .html(htmlString) to insert an image after the dom has loaded, how can i add a listener to handle the images onload event? Is there a property I can check to see various images and if they have loaded?

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

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

发布评论

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

评论(2

冷默言语 2024-09-09 11:46:10

添加 html 后,您可以将加载事件绑定到包含的图像:

$("#foo").html(htmlString).find("img").one("load", function() {
    ...
}).each(function() {

    // image has been cached, so load event won't fire unless we explicitly call it
    if(this.complete) $(this).trigger("load");
});

After appending your html, you can bind the load event to the contained images:

$("#foo").html(htmlString).find("img").one("load", function() {
    ...
}).each(function() {

    // image has been cached, so load event won't fire unless we explicitly call it
    if(this.complete) $(this).trigger("load");
});
旧夏天 2024-09-09 11:46:10

检查图像的 complete 属性

Check the complete property of the image(s)

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