09月27, 2017

兼容ie,火狐浏览器事件

var EventUtil ={
    addHandler: function(element, type, handler){
        if(element.addEventListener){//标准浏览器webkit,ff
            element.addEventListener(type, handler, false);
        }
        else if(element.attachEvent){//ie
            element.attachEvent('on' + type,handler);
        }else{
            element['on' + type] = handler;
        }
    },
    removeHandler: function(){
        if(element.removeEventListener){
            element.removeEventListener(type, handler, false);
        }else if(element.detachEvent){
            element.detachEvent('on' + type, handler);
        }else{
            element['on' + type] = null;
        }
    }
}

本文链接:http://blog.wxink.xyz/post/event.html

-- EOF --

Comments