1, AddEventListener
The standard method for AddEventListener binding events, such as the following, in which the order of execution and binding order of events is consistent and the order of execution is method1->method2->method3
//element.addEventListener(type,listener,useCapture);
btn1Obj.addEventListener("click",method1,false);
btn1Obj.addEventListener("click",method2,false);
btn1Obj.addEventListener("click",method3,false);
2, Attachevent
In IE8 and the following versions, AddEventListener is not supported, only attachevent bound events, and the order of execution is method3->method2->method1
//object.attachEvent(event,function);
btn1Obj.attachEvent("onclick",method1);
btn1Obj.attachEvent("onclick",method2);
btn1Obj.attachEvent("onclick",method3);
3. Attribute Assignment method Binding event
Applying this method overrides the method that is bound later, to bind multiple at once (multiple operations can be performed at one time, multiple methods may be called in an event)
obj.onclick=method1;
obj.onclick=method2;
obj.onclick=method3;
Bind multiple at once:
obj.onclick=function (){
method1();
method2();
method3();
}
JS Add the difference between event attachevent and AddEventListener