js 事件处理
<script>
var btn=document.getElementById("btn1");
btn.onclick= function(){alert("hello DOM0级事件处理程序1")};
btn.onclick= function(){alert("hello DOM0级事件处理程序2")};
btn.onclick= function(){alert("hello DOM0级事件处理程序3")};//被覆盖掉
btn.onclick=null;
</script>
-->
<script>
var btn1=document.getElementById("btn1").addEventListener("click",demo1);
var btn2=document.getElementById("btn1").addEventListener("click",demo2);
function demo1(){
alert("DOM2级事件处理1");
}
function demo2(){
alert("DOM2级事件处理2");
}
btn1.removeEventListener("click",demo1);
var b=document.getElementById("btn1");
if(b.addEventListener)
{
b.addEventListener("click".demo);
}else if(b.attachEvent){
b.attachEvent("onclick",demo);
}else{
btn1.onclick=demo();
}
function demo(){
alert("hello");
}
</script>