事件对象——跨浏览器的事件对象

var eventUntil={
    addHandler:(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;
        },
        getEvent:(event)=>{
            return event?event:window.event;
        },
        getTarget:(event)=>{
            return event.target||event.srcElement;
        },
        preventDefault:(event)=>{
            if(event.preventDefault){
                event.preventDefault();
            }else{
                event.returnValue=false;
            }
        },
        removeHandler:(element,type,handler)={
            //some code
        },
        stopPropagation:(event)=>{
            if(event.stopPropagation){
                event.stopPropagation();
            }else{
                event.cancelBubble=true;
            }
        }
};

 

posted @ 2020-02-03 12:09  Syinho  阅读(149)  评论(0编辑  收藏  举报