如果把removeHandler这个句柄删除或者注释后 eventUtil.addHandler(btn3,'click',showMes); 才可以执行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<input type="button" value="按钮3" id="btn3">
</div>
<script type="text/javascript">
function showMes(){
alert("hello world!");
}
var btn3=document.getElementById("btn3");
var eventUtil={
//添加句柄
addHandler:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
}
else if (element.attachEvent) {
element.attachEvent("on"+type,handler);
}
else{
element["on"+type]=handler;
}
}
//删除句柄
removeHandler:function(element,type,handler){
if(element.removeEventListener){
element.removeEventListener(type,handler,false);
}
else if (element.detachEvent) {
element.detachEvent("on"+type,handler);
}
else{
element["on"+type]=null;
}
}
}
eventUtil.addHandler(btn3,"click",showMes);
</script>
</body>
</html>