[英]What is the difference of using addEventListener?
What is the main difference between of using this... 使用这个的主要区别是什么......
document.addEventListener('mousedown', function() {
// code
}, false);
...and this? ...还有这个?
document.onmousedown = function() {
// code
}
Will there be any different result or any cause? 会有任何不同的结果或任何原因吗?
onclick
is a property, like the onclick
attribute can be placed in HTML. onclick
是一个属性,就像onclick
属性可以放在HTML中一样。 It has best browser support, however, it is primitive, as reassigning it overwrites the first (like any object property). 它有最好的浏览器支持,但是,它是原始的,因为重新分配它会覆盖第一个(就像任何对象属性一样)。
addEventListener()
, as the name suggests, allows you to register multiple callbacks for an element and event type. 顾名思义,
addEventListener()
允许您为元素和事件类型注册多个回调。 This allows you to have multiple mousedown
events for the same element. 这允许您为同一元素提供多个
mousedown
事件。 Before IE9, IE had their own attachEvent()
which is similar (you must specify the on
part too with attachEvent()
). 在IE9之前,IE有自己的
attachEvent()
类似(你必须使用attachEvent()
指定on
部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.