<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
window.onload = function(){
console.log('load2')
}
document.body.onload = function(){
console.log('load1')
}
document.body.addEventListener('load',function(){
console.log('load3')
})
</script>
<img src="xxxxx">
</body>
</html>
以上代码,load3
总是出不来
阿神2017-04-10 15:04:03
window.onload与document.body.onload在不同的浏览器间不同的表现
详见:http://w3help.org/zh-cn/causes/SD9022
addEventListener('onload',listener,useCapture)是在window里才执行
阿神2017-04-10 15:04:03
target.addEventListener(type, listener, useCapture);
Firefox浏览器支持addEventListener()
,IE是attachEvent()
;
document.body.addEventListener( 'onload',function() {
console.log('load3');
},false);
document.body.attachEvent('load',function(){
console.log('load3');
})