jquery on 添加img事件

//事件绑定成功
$("img").on("error",function(){
$(this).attr("src","/images/imgerr.jpg");
});


//事件绑定失败
$(document).on("error","img",function(){
$(this).attr("src","/images/imgerr.jpg");
});

猜测原因:
在所有的浏览器,load ,scroll, 和 error 事件(例如, 在一个 <img> 元素上)不会冒泡。在Internet Explorer 8和更低,paste 和 reset事件不会冒泡,这样的事件是不支持委派使用,但若事件处理函数是直接绑定在产生事件的元素上的话,是可以使用这些事件的。



$("img").one("error",function(){
$(this).attr("src","images/serve/request_cost_hospital.png");
});

猜你喜欢

转载自15757126299.iteye.com/blog/2286229