1

<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、インデックスの大きな円。

4

1 に答える 1

1

このコードから使用できます:

$('#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);
});

デモを試す

于 2012-11-11T12:59:22.107 に答える