Skip to content

Instantly share code, notes, and snippets.

@wdfx100
Created March 29, 2013 00:53
Show Gist options
  • Save wdfx100/5268018 to your computer and use it in GitHub Desktop.
Save wdfx100/5268018 to your computer and use it in GitHub Desktop.
IE与chrome及其他跨浏览器的时间对象对象eventUtil.js
var eventUtil={
addHandler:function(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;
}
},
removeHandler:function(element,type,handler){
if(element.removeEventListener){
element.removeEventListener(type,handler,false);
}else if(element.detachEvent){
element.detachEvent("on"+type,handler);
}else{
element["on"+type]=null;
}
},
getEvent:function(event){
return event ? event:window.event;
},
getTarget:function(e){
if(e.target){
return e.target;
}else{
return e.srcElement;
}
},
preventDefault:function(e){
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue=false;
}
},
stopPropagation:function(e){
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble=true;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment