简体   繁体   English

Javascript / jQuery HasLoaded或等效版本?

[英]Javascript/jQuery HasLoaded or equivalent?

I know in jquery it is possible to call the javascript/jquery onload() / load() functions on, for example an image ( <img> ). 我知道在jquery中可以调用javascript / jquery onload() / load()函数,例如图像( <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? 但是,如果在jQuery中,如果我在加载dom后使用.html(htmlString)插入图像,我如何添加侦听器来处理图像onload事件? Is there a property I can check to see various images and if they have loaded? 有没有可以查看各种图像以及是否已加载的属性?

After appending your html, you can bind the load event to the contained images: 附加html之后,您可以将load事件绑定到所包含的图像:

$("#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");
});

检查图像的complete属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM