e=eventUtil.getEvent(e); alert(eventUtil.getType(e));
应该是JS代码错了吧!哪错了,导致我这两行功能实现不出来
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;
},
getType:function(event){
return event.type;
},
preventDefault:function(event){
if (event.preventDefault) {
event.preventDefault();
}else{
event.returnValue=false;
}
},
stopPropagation:function(event){
if(event.stopPropagation){
event.stopPropagation();
}else{
event.cancelBubble=true;
}
}
}
window.onload=function(){
//函数
//获取元素
var wrap=document.getElementById("wrap");
var go=document.getElementById('go');
//添加事件
eventUtil.AddHandler(wrap,'click',function(){
alert("DOM文档");
});
eventUtil.AddHandler(go,'click',function(e){
e=eventUtil.getEvent(e);
alert(eventUtil.getType(e));
});
}
看不出问题 ,html发来看看