JavaScript Event Basics Summary "Mind mapping"

Source: Internet
Author: User

varEventutil = {    //Registering Eventsaddhandler:function (element, type, handler) {if(Element.addeventlistener) {Element.addeventlistener (type, handler,false); } Else if(element.attachevent) {element.attachevent (" on"+type, handler); } Else{element[" on"+ Type] =handler; }    },     //Removing eventsremovehandler:function (element, type, handler) {if(Element.removeeventlistener) {Element.removeeventlistener (type, handler,false); } Else if(element.detachevent) {element.detachevent (" on"+type, handler); } Else{element[" on"+ Type] =NULL; }    },     //Get EventGetevent:function (Event){        return Event?Event: Window.Event; },     //Get event nameGettarget:function (Event){        return Event. Target | |Event. srcelement; },        //Get mouse buttonGetbutton:function (Event){        //DOM2 detection of mouseevents modules        if(Document.implementation.hasFeature ("mouseevents","2.0")){            return Event. Button; //var k = Event.button; //switch (k) {//Case 0://return "0: Indicates left key"; //Case 1://return "1: Medium Key"; //Case 2://return "2: Right button"; //     }            //ie6,7,8 Left: 1, Middle key: 4, right-click: 2; //chrome,ff,ie9+ Left: 0, Middle key: 1, right-click: 2;}Else {            Switch(Event. button) {//ie under                 Case 0:                 Case 1://left button                 Case 3://key around                 Case 5://Left middle button                 Case 7://Right and left.                    return 0;//left button                 Case 2://Right-click                 Case 6://Right Middle                    return 2;//Right-click                 Case 4:return 1;//Middle Key            }        }    },        //get key coded valuesGetcharcode:function (Event){        if(typeof Event. CharCode = =" Number"){            return Event. CharCode; } Else {            return Event. keycode; }    },        /*The Relatedtarget property of the event object provides information about the element that contains the value only for mouseover and mouseout events; * For other events, the value of this property is null.    *ie does not support the Relatedtarget property, but it provides different properties that hold the same information.    * When the MouseOver event is triggered, the fromelement attribute of IE is the relevant element in the save rate; * When the Mouseout event is triggered, the toelement attribute of IE is stored in the relevant element. */Getrelatedtarget:function (Event){        if(Event. Relatedtarget) {            return Event. Relatedtarget; } Else if(Event. Toelement) {            return Event. toelement; } Else if(Event. Fromelement) {            return Event. fromelement; } Else {            return NULL; }        },        //Get mouse wheel MouseWheel eventGetwheeldelta:function (Event){        if(Event. Wheeldelta) {            return(Client.engine.opera && Client.engine.opera <9.5? -Event. Wheeldelta:Event. Wheeldelta); } Else {            return-Event. Detail * +; }    },        //cancels the default behavior of the event, and if Cancelable is true, this method can be used;//For example, to prevent access to the Herf property when a hyperlink is clickedPreventdefault:function (Event){        if(Event. Preventdefault) {            Event. Preventdefault (); } Else {            Event. returnvalue =false; }    },        //cancels further capture or bubbling of the event. This method can be used if Bubbles is true;Stoppropagation:function (Event){        if(Event. Stoppropagation) {            Event. Stoppropagation (); } Else {            Event. cancelbubble =true; }    },     //get Clipboard textGetclipboardtext:function (Event){        varClipboarddata = (Event. clipboarddata | |window.clipboarddata); returnClipboarddata.getdata ("text"); },     //set Clipboard textSetclipboardtext:function (Event, value) {        if(Event. Clipboarddata) {            Event. Clipboarddata.setdata ("Text/plain", value); } Else if(window.clipboarddata) {Window.clipboardData.setData ("text", value); }    } };

JavaScript Event Basics Summary "Mind mapping"

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.