Skip to content

Instantly share code, notes, and snippets.

@zhuzhuaicoding
Created November 2, 2012 05:07
Show Gist options
  • Select an option

  • Save zhuzhuaicoding/3998837 to your computer and use it in GitHub Desktop.

Select an option

Save zhuzhuaicoding/3998837 to your computer and use it in GitHub Desktop.
addEvent basic
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);//DOM2.0
return true;
}
else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);//IE5+
return r;
}
else {
elm['on' + evType] = fn;//DOM 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment