如果出现错误,如何使用自动图像重新加载来构建<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,索引上的大圆圈。
如果出现错误,如何使用自动图像重新加载来构建<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
});
这很简单,因为你有图像 url,你可以重新加载它并在图像中替换它。
更新
$("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);
});