Quantcast
Channel: w3cplus
Viewing all articles
Browse latest Browse all 1557

跨浏览器事件对象

$
0
0
var EventUtil = {
    addHandler: function(elem,type,handler){
	if (elem.addEventListener) {
		elem.addEventListener(type, handler, false);
	}else if(obj.attachEvent){
		elem.attachEvent('on'+type,handler);
	}else{
        	elem["on"+type] = handler;
        }
    },
    removeHandler: function(elem,type,handler){
	if (elem.removeEventListener) {
		elem.removeEventListener(type, handler, false);
	}else if(obj.attachEvent){
		elem.detachEvent('on'+type,handler);
	}else{
        	elem["on"+type] = handler;
        }
    },
    getEvent: function(){
    	return event ? event : window.event;
    },
    getTarget: function(){
    	return event.target || event.srcElement;
    },
    preventDefault: function(){
    	if(event.preventDefault){
        	event.preventDefault;
        }else{
        	event.returnValue = false;
        }
    },
    stopPropagation: function(event){
    	if(event.stopProgation){
        	event.stopProgation;
        }else{
        	event.cancalBubble = true;
        }
    }
};

 


Viewing all articles
Browse latest Browse all 1557

Trending Articles