addEventListener绑定事件不覆盖之前的代码:
var btn1Obj = document.getElementById("btn1"); btn1Obj.addEventListener("click",method1,false); btn1Obj.addEventListener("click",method2,false); btn1Obj.addEventListener("click",method3,false);
执行顺序为method1->method2->method3
on添加监听会覆盖前面的监听:
document.getElementById("btn").onclick = method1; document.getElementById("btn").onclick = method2; document.getElementById("btn").onclick = method3;
如果这样写,那么将会只有medhot3被执行