运行不了啊,是什么错误啊?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>星期</title>
<input type="button" id="btn" value="按钮1" onclick="showMes()"/>
<input type="button" id="btn2" value="按钮2"/>
<input type="button" id="btn3" value="按钮3"/>
</head>
<body>
<script>
function showMes(){
alert("HelloWorld");
}
function canter(){
alert("DOM2级事件触发了!")
}
function hwy(){
alert("IE事件触发了!")
}
var btn3 = document.getElementById("btn3");
//DOM 0级事件
var btn2 = document.getElementById("btn2");
/*btn2.onclick = function(){
alert('DOM0级事件触发了!');
}
//DOM 2级事件
var btn3 = document.getElementById("btn3");
//btn3.addEventListener('click',canter,false);
//IE事件
btn3.attachEvent('onclick',hwy);*/
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>