问答详情
源自:2-4 IE事件处理程序及跨浏览器解决

点击按钮3没有反应是为什么呢,removeHandler的颜色和addHandler的颜色不一样

var eventUtil={  
    //addHandler 添加句柄
    addHandler:function(element,type,handler){
        if(element.addEventListener){
            element.addEventListener(type,handler,false);
        }else if(element.attachEvent){//IE
            element.attachEvent('on'+type,handler);
        }else{
            element['on'+type]=handler;
            // element['onclick']===element.onclick
        }
    },
     // 删除句柄
    removeHandler:function(element,type,handler){
        if(element.removeEventListener(){
            element.removeEventListener(type,handler,false);
        }else if(element.detachEvent){//IE
            element.detachEvent('on'+type,handler);
        }else{
            element['on'+type]=null;
        }
    }
}

eventUtil.addHandler(btn3,'click',showMessage);


提问者:緣来 2019-06-26 09:38

个回答

  • 緣来
    2019-06-26 09:42:20

    多加了半个括号!