Javascript/jQuery HasLoaded或同等功能? [英] Javascript/jQuery HasLoaded or equivalent?
本文介绍了Javascript/jQuery HasLoaded或同等功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在jquery中可以调用javascript/jquery onload()
/load()
函数,例如图像(<img>
).
I know in jquery it is possible to call the javascript/jquery onload()
/load()
functions on, for example an image (<img>
).
但是,如果在jQuery中,如果我在加载dom后使用.html(htmlString)
插入图像,我如何添加侦听器来处理图像onload事件?是否可以查看各种图像以及是否已加载这些图像?
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?
推荐答案
附加html之后,您可以将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");
});
这篇关于Javascript/jQuery HasLoaded或同等功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文