Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save zhuzhuaicoding/3998816 to your computer and use it in GitHub Desktop.
addEvent
var addEvent=(function(){
if(document.addEventListener){
return function(el,type,fn){
if(el.length){
for(var i=0;i<el.length;i++){
addEvent(el[i],type,fn);
}
}else{
el.addEventListener(type,fn,false);
}
};
}else{
return function(el,type,fn){
if(el.length){
for(var i=0;i<el.length;i++){
addEvent(el[i],type,fn);
}
}else{
el.attachEvent('on'+type,function(){
return fn.call(el,window.event);
});
}
};
}
})();
@zhuzhuaicoding

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment