Live()关键字无法使用动态html图像加载 [英] Live() keyword not working on load with dynamic html images
问题描述
我将图像动态添加到页面中,我似乎无法通过live()动态地使用'load'事件。
I have images being dynamically added to a page, I don't seem to be able to get the 'load' event working dynamically with live().
这是我目前的代码:
$('#largeImg' + nextUniqueItemID).hide();
$('#largeImg' + nextUniqueItemID).live('load' , function() {
$('#loader' + nextUniqueItemID).hide();
$('#largeImg' + nextUniqueItemID).show();
});
'#largeImg'+ nextUniqueItemID
正在在函数前面添加到页面的图像,'#largeImg'+ nextUniqueItemID
是加载图像。
with '#largeImg' + nextUniqueItemID
being an image that was added to the page earlier in the function and '#largeImg' + nextUniqueItemID
being a loading image.
我觉得好像我可能会误用直播,因为它不需要听众,而是立即触发事件。
I feel as if I may be misusing "live" as it doesn't really need a listener but to trigger the event immediately.
感谢您的帮助。我试过绑定而且从未触发过。我也尝试消除负载,但这不起作用。有没有办法将一个监听器附加到一个事件,指示图像何时加载?
Thanks for all your help. I tried "bind" and that never triggered. I also tried doing away with the load, but that didn't work. Is there a way to attach a listener to an event that would indicate when the image was done loading?
推荐答案
我最终得到了什么做的是将load事件直接放在我的图像的onLoad =事件中。结果很好。
What I ended up doing was putting the load event directly in my image's onLoad="" event. That worked out.
这篇关于Live()关键字无法使用动态html图像加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!