1

img load through on でエラーを取得しようとしていますが、うまくいきません

$(document).on("error","#someid img",
               function(){
                  console.log("Image load error through On");
              });

しかし、「バインド」でも同様に機能します

$("#someid img").bind("error", function() {
                         console.log("Image load error through bind");
                      });
4

2 に答える 2

2

問題は、errorイベントがバブリングしないため、イベント委任を使用してdocumentレベルでキャプチャできないことです。

それをキャプチャする唯一の方法は、要素に直接バインドすることです。


これは、ハンドラーでオブジェクトの.bubblesプロパティを使用して決定できます。event.bind()

$("#someid img").bind("error", function(event) {
    console.log(event.bubbles); // false
});
于 2013-09-26T14:45:33.457 に答える