1

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

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

4

2 回答 2

2

添加 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");
});
于 2010-05-17T14:50:36.987 回答
1

检查complete图像的属性

于 2010-05-17T14:57:51.027 回答