What is the difference of using addEventListener?

后端 未结 1 711
野的像风
野的像风 2020-12-31 18:58

What is the main difference between of using this...

document.addEventListener(\'mousedown\', function() {
    // code
}, false);

...and th

相关标签:
1条回答
  • 2020-12-31 19:12

    onclick is a property, like the onclick attribute can be placed in 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. This allows you to have multiple mousedown events for the same element. Before IE9, IE had their own attachEvent() which is similar (you must specify the on part too with attachEvent()).

    0 讨论(0)
提交回复
热议问题