유니버설 이벤트 탐지기

2025 단어
 // 
        var eventWatch={
            readyEvent:function(fn){
                if(fn==null){
                    fn=document
                }
                var oldonload=window.onload;
                if(typeof window.onload!='function'){
                    window.onload=fn;
                }else{
                    window.onload=function(){
                        oldonload();
                        fn();
                    }
                }
            }
            // 
            addEvent:function(ele,type,handler){
                if(ele.addEventListener){
                    ele.addEventListener(type,handler,false)
                }else if(ele.attachEvent){
                    ele.attachEvent('on'+type,function(){
                        handler.call(ele)
                    })
                }else{
                    ele['on'+type]=handler;
                }
            }
            // 
            removeEvent:function(ele,type,handler){
                if(ele.removeEventListener){
                    ele.removeEventListener(type,handler,false);
                }else if(ele.detachEvent){
                    ele.detachEvent('on'+type,handler)
                }else{
                    ele['on'+type]=null;
                }
            }
            // 
            stopPropagation:function(e){
                var ev=e || window.event;
                if(ev.stopPropagation){
                    ele.stopPropagation();
                }else{
                    ev.cancleBubble=true;
                }
            }
            // 
            preventDefault:function(e){
                var ev=e || window.event;
                if(ev.preventDefault){
                    ev.preventDefault();
                }else{
                    ev.returnValue=0;
                }
            }
            // 
            getTarget:function(){
                return event.target || event.srcElement
            }

        }

좋은 웹페이지 즐겨찾기