按钮5和6都没反应
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>事件</title>
</head>
<body>
<input type="button" value="按钮1" onclick="alert('111')"/>
<input type="button" value="按钮2" onclick="aaa()"/>
<input type="button" value="按钮3" id="but3"/>
<input type="button" value="按钮4" id="but4"/>
<input type="button" value="按钮5" id="but5"/>
<input type="button" value="按钮6" id="but6"/>
<script type="text/javascript">
//html方法
function aaa(){
alert("222");
}
//DOM0级
var but3=document.getElementById("but3");
but3.onclick=function(){alert("333");};
//DOM2级
var but4=document.getElementById("but4");
but4.addEventListener("click",aaa,false);
//but4.removeEventListener("click",aaa,false);
//IE
var but5=document.getElementById("but5");
but5.attachEvent("onclick",aaa);
//but5.detachEvent("onclick",aaa);
//跨浏览器
var eventUtil={
addevent:function(ele,type,hander){
if(ele.addEventListener){
ele.addEventListener(type,hander,false);
}
else if(ele.attachEvent){
ele.attachEvent("on"+type,hander);
}
else{
ele["on"+type]=hander;
//ele.onclick===ele["onclick"];
}
},
removeevent:function(ele,type,hander){
if(ele.removeEventListener){
ele.removeEventListener(type,hander,false);
}
else if(ele.detachEvent){
ele.detachEvent("on"+type,hander);
}
else{
ele["on"+type]=null;
}
}
};
var but6=document.getElementById("but6");
eventUtil.addevent(but6,"click",aaa);
//but6.attachEvent("onclick",aaa);
</script>
</body>
</html>