事件调用兼容问题,为什么不行呢
var eventUtil={
//添加事件
addHandler:function(element,type,funName){
if(element.addEventListener){//DOM2级
element.addEventListener(type,funName,false);
} else if(element.attachEvent){//IE浏览器
element.attachEvent('on'+type,funName);
}else{//DOM0级
element['on'+type]=funName;
}
}
//删除事件
removeHandler:function(element,type,funName){
if(element.removeEventListener){//DOM2级
element.removeEventListener(type,funName,false);
} else if(element.detachEvent){//IE浏览器
element.detachEvent('on'+type,funName);
}else{//DOM0级
element['on'+type]=null;
}
}
}
window.onload=function(){
var btn = document.getElementById('btn');
eventUtil.addHandler(btn,'click',show);
function show(){
alert('a');
};
}