我这个是什么问题,代码跟老师一样呀,谁帮我看看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
var btn1=document.getElementById("btn1");
// var box=document.getElementById("box");
// function showBox(){
// alert("box");
// }
function showBtn(event){
alert(event.type);
}
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(btn1,'click',showBtn);
// eventUtil.addHandler(box,'click',showBox);
</script>
</head>
<body >
<!--<div id="box">-->
<input type="button" value="button" id="btn1"/>
<!--</div>-->
</body>
</html>