-
-
Save wdfx100/5268018 to your computer and use it in GitHub Desktop.
IE与chrome及其他跨浏览器的时间对象对象eventUtil.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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