1Addevent:function(el,type,fn,capture) {2 if(window.addeventlistener) {3 if(Type = = = "MouseWheel" && Document.mozhidden!==undefined) {4Type = "Dommousescroll";5 } 6El.addeventlistener (Type, FN,!!)capture);7}Else if(window.attachevent) {8El.attachevent ("on" +type, fn);9 }Ten }, OneRemoveevent:function(el,type,fn,capture) { A if(window.removeeventlistener) { - if(Type = = = "MouseWheel" && Document.mozhidden!==undefined) { -Type = "Dommousescroll"; the } -El.removeeventlistener (Type, FN,!!)capture); -}Else if(window.detachevent) { -El.detachevent ("on" +type, fn); + } - }, + //compatibility handling of mouse wheel AEventcompat:function(e) { ate | | (E =window.event); - varType =E.type; - if(Type = = ' Dommousescroll ' | | type = = ' MouseWheel ') { -E.delta = (E.wheeldelta)? -e.wheeldelta/120: (E.detail | | 0)/3; - } - //alert (e.delta); in if(E.srcelement &&!)e.target) { -E.target =e.srcelement; to } + if(!e.preventdefault) { -E.preventdefault =function() { theE.returnvalue =false; * }; $ }Panax Notoginseng if(!e.stoppropagation && e.cancelbubble!==undefined) { -E.stoppropagation =function() { theE.cancelbubble =true; + }; A } the /* + ...... Some other compatibility processing*/ - returne; $ }, $Bindaseventlistener:function(context, fun) { - varSelf = This; - return function(e) { the returnFun.call (Context, Self.eventcompat (e)); - }Wuyi } the - Wu //Call: - varDom = document.getElementById (' btn '); About varObject = { $Clickctrl:function(e) { - alert (e); - } - }; A +Addevent (DOM, "click",function(){ the alert (dom.id); - }); $ theAddevent (DOM, "MouseDown", theBindaseventlistener (Object,function(e) { the object. Clickctrl (e); the}));
A compatible notation for JS event monitoring