Skip to content

Instantly share code, notes, and snippets.

@winwu
Created October 15, 2013 12:25
Show Gist options
  • Save winwu/6990804 to your computer and use it in GitHub Desktop.
Save winwu/6990804 to your computer and use it in GitHub Desktop.
403 圖片偵測加強版(ajax偵測)
function detect_if_image_loaded(){
$('img').bind('error', function (e) {
var e = e.type;
switch(e){
case 'error':
$(this).attr('src','/images/no_img.png');
break;
}
});
}
//第一次載入的時候不是ajax,所以先叫一次
detect_if_image_loaded();
$(document).ajaxStop(function() {
detect_if_image_loaded();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment