到底代码哪里错了
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;
}
},
//获取一个兼容所有浏览器的事件对象
getEvent: function(event){
return (event?event:window.event);
}
}
window.onload=function(){
//函数
//获取元素
var wrap=document.getElementById("wrap");
var btn2=document.getElementById('btn2');
//添加事件
eventUtil.AddHandler(wrap,'click',function(){
alert("DOM文档");
});
eventUtil.AddHandler(btn2,'click',function(e){
e=eventUtil.getEvent(e);
alert(e.type);
});
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/js1.js"></script>
<script src="js/jsMain.js"></script>
</head>
<body>
<div id="wrap">
<input type="button" name="btn" id="btn1" value="按钮一" onclick="m()" />
<input type="button" name="btn" id="btn2" value="按钮二" />
<input type="button" name="btn" id="btn3" value="按钮三" />
<a href="1.html" id="go">链接</a>
</div>
</body>
</html>