document.getElementById("btn").onclick = method1;
document.getElementById("btn").onclick = method2;
document.getElementById("btn").onclick = method3;
如果这样写,那么将会只有medhot3被执行
如需要三个方法都执行,则要用到attachEvent和addEventListener
html
<button id="btn1">button</button>
js
<script>
var btn1Obj = document.getElementById("btn1");
//object.attachEvent(event,function);
if(btn1Obj.attachEvent){
btn1Obj.attachEvent("onclick",method1); //method3>method2>method1
btn1Obj.attachEvent("onclick",method2);
btn1Obj.attachEvent("onclick",method3);
}else{
btn1Obj.addEventListener("click",method1,false); //注意不是onclick而是click.FF是顺序进行的,method1>method2>method3
btn1Obj.addEventListener("click",method2,false);
btn1Obj.addEventListener("click",method3,false);
}
function method1(){alert("1111");}
function method2(){alert("2222");}
function method3(){alert("3333");}
</script>