1
$(function() { /*jquery .ready()*/
var thumb_img = new Image();
thumb_img.id = 'cid_' + 1730;
thumb_img.src = "";
$(thumb_img).on('load', function() {
console.log("Image loaded " + thumb_img.src);
}).error(function(){
console.log("ERROR loading image " + thumb_img.src);
});
thumb_img.src = 'https://fiddle.jshell.net/img/logo.png';
});
結果在控制檯:.on()工作時,爲什麼.error()被調用? (IE11)
Image loaded https://fiddle.jshell.net/img/logo.png
ERROR loading image https://fiddle.jshell.net/img/logo.png
我只想.error()如果圖像不能被加載到被調用。這似乎只發生在IE(使用11)。
使用jQuery 2.0.2
你使用的是什麼jQuery版本。從v1.8開始,'error()'被棄用。嘗試'on('error',handler)'附加到'error'事件 – lscmaro
編輯我的問題以包含版本(2.0.2)。我也試過你的代碼,它沒有修復它。 '.on('error',function(){console.log(「ERROR loading image」+ thumb_img.src「);});' – AllisonC