var imgLoader = $("<img />"); $(imgLoader).attr("src","http://localhost/malevil/Content/Images/img_adrenalin.jpg"); $(imgLoader).unbind('load'); $(imgLoader).bind('load',function () { alert("event fired"); });
但这项工作仅限于Chrome,问题出在哪里?
在IE中,Firefox和Opera加载事件从未被解雇.
解决方法
在设置src属性之前,需要绑定load事件.
作为旁注,您需要了解图像上的加载事件的已知问题:
> javascript,image onload() doesnt fire in webkit if loading same image
- It doesn’t work consistently nor
reliably cross-browser- It doesn’t
fire correctly in WebKit if the image
src is set to the same src as before- It doesn’t correctly bubble up the
DOM tree- Can cease to fire for images that already live in the browser’s cache