<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<button id="btn1">点这里</button>
<script>
var btn1=document.getElementById("btn1");
var eventUtil={
addHandler:function(e,type,handler){
if(e.addEventListener){
e.addEventListener(type,handler);
}
else if(e.attachEvent){
e.attachEvent('on'+type,handler);
}
else{
e['on'+type]=handler;
}
},
removeHandler:function(e,type,handler){
if(e.removeEventListener){
e.removeEventListener(type,handler,false);
}
else if(e.detachEvent){
e.detachEvent('on'+type,handler);
}
else{
e['on'+type]=null;
}
}
}
eventUtil.addHandler(btn1,'click',ceshi);
function ceshi(){alert(123)};
</script>
</body>
</html>
//script脚本必须放在button定义下面,不理解y?