0
我知道$('img').load(function(){})
可以工作。不過,我想img dom
那些最初還沒有創建的也可以trigger the event
。我想知道爲什麼下面不起作用。如何綁定img的加載事件
$(window.document).on('load', 'img', function(){
console.log('load', this);
})
我知道$('img').load(function(){})
可以工作。不過,我想img dom
那些最初還沒有創建的也可以trigger the event
。我想知道爲什麼下面不起作用。如何綁定img的加載事件
$(window.document).on('load', 'img', function(){
console.log('load', this);
})
jQuery不支持捕獲。所以我不得不使用js的addEventListener。
document.body.addEventListener(
'load',
function(event){
var tgt = event.target;
if(tgt.tagName == 'IMG'){
console.log('load', tgt.src);
}
},
true
)
不能因爲[負載事件](https://developer.mozilla.org/en-US/docs/Web/Events/load)不起泡,所以它不支持委託處理程序 –
謝謝。我找到了正確的方法。它不是因爲泡沫而是捕獲模型。 – chengjiang