开发者

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜