1, AddEventListener
This method is used to add an event handle to the specified element
Browser support is chrome1.0, ie9+, fireFox1.0, opera7.0
The method contains three parameters event, function, Usecapture
Event is specified, no "on" prefix is required
Functions executed when the function is triggered by an event
USECAPTURE Specifies whether the event is executed in the capture or bubbling phase, true indicates that the event is executed during the capture phase, false means execution during the bubbling phase (when the target element defines the same event as the ancestor element, such as a click event, and if the event captures the click event of the ancestor element when the target element is clicked), Trigger the hit event of the target element, while event bubbling will trigger the target element event and then the ancestor element event.
2, Attachevent
Functionality is the same as the AddEventListener method, only available for IE8 and earlier browsers and opera7.0 and earlier versions
The method consists of two parameters event,function
Event is specified, and an "on" prefix is required
Functions executed when the function is triggered by an event
Since IE8 and earlier browsers only support bubbling events and do not support capture, there is no setting for the third parameter
AddEventListener and Attchevent in JavaScript