JS Event compatible processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.