我试图让img加载错误通过,但它不起作用
$(document).on("error","#someid img",
function(){
console.log("Image load error through On");
});但类似的工作与“绑定”
$("#someid img").bind("error", function() {
console.log("Image load error through bind");
});发布于 2013-09-26 14:45:33
问题是error事件不冒泡,所以不能使用事件委托在document级别捕获它。
捕获它的唯一方法是直接绑定到元素。
您可以通过在.bubbles处理程序中对event对象使用.bind()属性来确定这一点。
$("#someid img").bind("error", function(event) {
console.log(event.bubbles); // false
});发布于 2013-09-26 14:40:52
$("#your_id").error(function () {
alert("your text")
})on()在jquery1.7之后取代.bind(), .live() and .delegate()。https://stackoverflow.com/questions/19031178
复制相似问题