JavaScript 事件对象的兼容性方案
HTML:
<div>123</div>
CSS:
div {
width: 100px;
height: 100px;
background-color: pink;
}
JS:
传统注册方式:
var div = document.querySelector('div');
div.onclick = function(e) {
e = e || window.event;
console.log(e);
}
attachEvent事件监听方式:
div.addEventListener('click', function(e) {
e = e || window.event;
console.log(e);
})