JS Event Object Eventutil

Source: Internet
Author: User

1 varEventutil = {2GetEvent:function(event) {//Get Event Object3         returnEvent?event:window.event;4     },5AddHandler:function(element, type, handler) {//Binding Events6         if(element.addeventlistener) {7Element.addeventlistener (type, Handler,false);8}Else if(element.attachevent) {9Element.attachevent ("on" +type, handler);Ten}Else { OneElement["on" + type] =handler; A              -         } -     }, theRemoveHandler:function(element, type, handler) {//Remove Bindings -         if(element.removeeventlistener) { -Element.removeeventlistener (Type,handler,false); -}Else if(element.detachevent) { +Element.detachevent ("On" +type,handler,false); -}Else{ +element["on" +type] =NULL; A         } at     }, -Preventdefault:function(event) {//Block Default Events -         if(event.preventdefault) { - Event.preventdefault (); -}Else{ -Event.returnvalue =false; in         } -     }, toStoppropagation:function(event) {//Block Event bubbling +         if(event.stoppropagation) { - event.stoppropagation (); the}Else{ *Event.cancelbubble =true; $         }Panax Notoginseng     }, -Getrelatetarget:function(event) {//information about event-related elements the         if(event.relatedtarget) { +             returnEvent.relatedtarget; A}Else if(event.toelement) { the event.toelement; +}Else if(event.fromelement) { -             returnevent.fromelement; $}Else{ $             return NULL; -         } -     }, theGetbutton:function(event) {//Detecting Button Properties -         if(Document.implementation.hasFeature ("Mouseevents", "2.0")){Wuyi             returnEvent.button; the}Else{ -             Switch(Event.button) { Wu                  Case0: -                  Case1: About                  Case3: $                  Case5: -                  Case7: -                         return0;//primary mouse button -                  Case2: A                  Case6: +                         return2;//Secondary mouse button the                  Case4: -                         return1;//Mouse wheel Button $             } the         } the     }, theGetwheeldelta:function(event) {//Mouse Scrolling property values the         if(Event.wheeldelta) { -             return(Client.engine.opera && client.engine.opera <9.5?-Event.wheelDelta:event.wheelDelta) in}Else{ the             return-event.detail *40; the         } About     }, theGetcharcode:function(event) {//Get character encoding the         if(typeofEvent.charcode = = "Number"){ the             returnEvent.charcode; +}Else{ -             returnEvent.keycode; the         }Bayi     }, theGetcilpboardtext:function(event) {//Get Clipboard contents the         varCilpboarddata = (Event.clipboarddata | |window.clipboarddata); -         returnClipboarddata.getdata ("Text"); -     }, theSetclipboardtext:function(Event,value) {//cut to shear plate the         if(event.clipboarddata) { the             returnEvent.clipboardData.setData ("Text/plain", value); the}Else if(window.clipboarddata) { -             returnWindow.clipboardData.setData ("Text", value); the         } the     } the 94  the}

The code is summarized in the JavaScript Advanced Programming Events section.

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.