varEventutil ={bindevent:function(EL, type, target, callback, popgation) {/** * @author Zhangtian * @date 2017/11/16 * @desc standard browser compatible with IE event * @augments el: Event Source Typ E Event Type callback callback function popgation whether bubble * @todo IE8 down with stoppropagation invalid, know the reason of the park workers please leave a message to inform or send me, thank you!!! */ varCaption = Caption | |true;//default is bubbling //If the event proxy is not used, the target null if((typeofTarget) = = "function") {Callback=Target; Target=NULL; } if(El.addeventlistener) {El.addeventlistener (type,function(e) {if(target) {Console.log ("Event Proxy"); if(E.target = =target) {Callback.call (target, e);//change this point, if not call,this point to window } } Else{Console.log ("Normal Event"); Callback.call (EL, E); //change this point, if not call,this point to window}}, Popgation); } Else if(el.attachevent) {el.attachevent ("On" + type,function() { varE =window.event; if(target) {Console.log ("Event Proxy"); if(E.target = =target) {Callback.call (target, e);//change this point, if not call,this point to window } } Else{Console.log ("Normal Event"); Callback.call (EL, E); //change this point, if not call,this point to window } }); }}, Stoppropagation:function(e) {varevent = e | |window.event; if(event.stoppropagation) {event.stoppropagation (); } Else{event.cancelbubble; }}, Preventdefault:function(e) {varevent = e | |window.event; if(Event.preventdefault) {event.preventdefault (); } Else{Event.returnvalue=false; } }};
JS Event compatible processing