>

window.addeventjs事件驱动函数集合addEvent等_javascri

- 编辑:金沙国际平台登录 -

window.addeventjs事件驱动函数集合addEvent等_javascri

//writtenbyDeanEdwards,2005 //withinputfromTinoZijdel,MatthiasMiller,DiegoPerini // functionaddEvent{ if(element.addEventListener){ element.addEventListener; }else{ //assigneacheventhandlerauniqueID ifhandler.$$guid=addEvent.guid++; //createahashtableofeventtypesfortheelement ifelement.events={}; //createahashtableofeventhandlersforeachelement/eventpair varhandlers=element.events[type]; if{ handlers=element.events[type]={}; //storetheexistingeventhandler if{ handlers[0]=element["on"+type]; } } //storetheeventhandlerinthehashtable handlers[handler.$$guid]=handler; //assignaglobaleventhandlertodoallthework element["on"+type]=handleEvent; } }; //acounterusedtocreateuniqueIDs addEvent.guid=1; functionremoveEvent{ if(element.removeEventListener){ element.removeEventListener; }else{ //deletetheeventhandlerfromthehashtable if(element.events&&element.events[type]){ deleteelement.events[type][handler.$$guid]; } } }; functionhandleEvent{ varreturnValue=true; //grabtheeventobject(IEusesaglobaleventobject) event=event||fixEvent(((this.ownerDocument||this.document||this).parentWindow||window).event); //getareferencetothehashtableofeventhandlers varhandlers=this.events[event.type]; //executeeacheventhandler for{ this.$$handleEvent=handlers[i]; if(this.$$handleEvent{ returnValue=false; } } returnreturnValue; }; functionfixEvent{ //addW3Cstandardeventmethods event.preventDefault=fixEvent.preventDefault; event.stopPropagation=fixEvent.stopPropagation; returnevent; }; fixEvent.preventDefault=function(){ this.returnValue=false; }; fixEvent.stopPropagation=function(){ this.cancelBubble=true; };

本文由金沙国际平台登录发布,转载请注明来源:window.addeventjs事件驱动函数集合addEvent等_javascri