jquery image not loading problem
does anybody knows how to check if an image loads properly. I have a script that preloa开发者_JS百科ds images and what I wanted to do is if the image doesn't exists, which causes my script not to end, I would just make the attribute "src" to be a default value
image.load(function(){
//it never reache here if the image doesn't exist
}).attr('src','a non existing image');
Thanks
var image = $('<img>').appendTo('body');
image.load(function() {
// image is found and loaded
}).error(function() {
// image not loaded
image.attr('src','default-image.jpg');
}).attr('src','a non existing image');
精彩评论