Skip to content

Instantly share code, notes, and snippets.

@icai
Created March 5, 2012 11:29
Show Gist options
  • Save icai/1977941 to your computer and use it in GitHub Desktop.
Save icai/1977941 to your computer and use it in GitHub Desktop.
addEventSimple & removeEventSimple
function addEventSimple(obj, evt, fn) {//常用函数
if (obj.addEventListener) // W3C
obj.addEventListener(evt, fn, false);
else if (obj.attachEvent) // Microsoft
obj.attachEvent('on' + evt, fn);
};
function removeEventSimple(obj, evt, fn) {
if (obj.removeEventListener)
obj.removeEventListener(evt, fn, false);
else if (obj.detachEvent)
obj.detachEvent("on" + evt, fn);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment