javascript – jQuery bind(“load”)

前端之家收集整理的这篇文章主要介绍了javascript – jQuery bind(“load”)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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

并且,引自jQuery manual on load():

  • It doesn’t work consistently nor
    reliably cross-browser @H_301_21@
  • It doesn’t
    fire correctly in WebKit if the image
    src is set to the same src as before@H_301_21@
  • It doesn’t correctly bubble up the
    DOM tree@H_301_21@
  • Can cease to fire for images that already live in the browser’s cache@H_301_21@
原文链接:https://www.f2er.com/jquery/154785.html

猜你在找的jQuery相关文章