如何构建<img>
发生错误时自动重新加载图像的加载事件?
图像的创建方式:
var Img = $(document.createElement('img'));
Img.on('load',function(){
// Some code, this handler must be saved
});
Img.attr('src',path);
Img.appendTo(...
使用地点:http://vseslava.ru ,索引上的大圆圈。
最佳答案
您可以从此代码中使用:
$('#image1')
.load(function(){
$('#result1').text('Image is loaded!');
})
.error(function(){
$('#result1').text('Image is not loaded!');
// in this case you must reload image with jQuery
});
这很简单,因为你有图像网址,你可以重新加载它并将其替换为图像。
更新
$("img").load(function(){
$('#result1').text('Image is loaded!\n');
})
.error(function(){
$('#result1').text('Image is not loaded!\n');
// in this case you must reload image with jQuery
var imgSrc = $(this).attr('src');
$(this).attr('src',imgSrc);
});
关于javascript - 图像加载事件,在出现错误时自动重新加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13331284/