我知道在 jquery 中可以调用 javascript/jquery onload()
/load()
函数,例如图像 ( <img>
)。
但是,如果在 jquery 中,如果我.html(htmlString)
在 dom 加载后插入图像,我如何添加一个侦听器来处理图像 onload 事件?是否有一个属性我可以检查以查看各种图像以及它们是否已加载?
我知道在 jquery 中可以调用 javascript/jquery onload()
/load()
函数,例如图像 ( <img>
)。
但是,如果在 jquery 中,如果我.html(htmlString)
在 dom 加载后插入图像,我如何添加一个侦听器来处理图像 onload 事件?是否有一个属性我可以检查以查看各种图像以及它们是否已加载?
添加 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
图像的属性