我知道在 jquery 中可以调用 javascript/jquery onload()
/load()
功能,例如图像(<img>
)。
但是,如果我在 jquery 中使用 .html(htmlString)
要在 dom 加载后插入图像,如何添加监听器来处理图像 onload 事件?是否有我可以检查的属性以查看各种图像以及它们是否已加载?
最佳答案
附加 html 后,您可以将加载事件绑定(bind)到包含的图像:
$("#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");
});
关于Javascript/jQuery HasLoaded 或等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2850011/