跨浏览器的事件对象EventUtil

var EventUtil = function(){
    /*--addHandler--*/
    addHandler:function(element,type,handler){
	if(element.addEventListener){
	    element.addEventListener(type,handler,false);
	}else{
	    element.attachEvent(‘on’+type,handler);
	}
    },
    /*--getEvent--*/
    getEvent:function(event){
	return event?event:window.event;
    },
    /*--getTarget--*/
    getTarget:function(event){
	return event.target || event.srcElement;
    },
    /*--preventDefault--*/
    preventDefault:function(event){
	if(event.preventDefault){
  	    event.preventDefault();
	}else{
	    event.returnValue = false;
	}
    },
    /*--removeHandler--*/
    removeHandler:function(){
	if(element.removeEventListener){
	     element.removeEventListener(type,handler,false);
	}else{
	    element.detachEvent(‘on’+type,handler);
	}
     },
     /*--stopPropagation--*/
     stopPropagation:function(){
	if(event.stopPropagation){
	    event.stopPropagation();
	}else{
  	    event.cancelBubble = true;
	}
     }
}

  

posted @ 2015-06-15 17:50  Rain-Heart  阅读(158)  评论(0编辑  收藏  举报