Common event handling Function JS Library

Source: Internet
Author: User

varEventutil = {            /** Add Event Handling Parameters: Element Object Event type handling function*/AddHandle:function(element, type, handle) {//event Additions at the dom2 level                if(Element.addeventlistener) {Element.addeventlistener (type, handle,false); } Else {                    //event Additions for IE                    if(element.attachevent) {element.attachevent (' On ' +type, handle); } Else {                        //assigning values to element attributeselement[' on ' + type] =handle; }                }            },            /** Remove Event Handling Parameters: Element Object Event type handling function*/RemoveHandle:function(element, type, handle) {//event Removal at the dom2 level                if(Element.removeeventlistener) {Element.removeeventlistener (type, handle,false); } Else {                    //event removal for IE                    if(element.detachevent) {element.detachevent (' On ' +type, handle); } Else {                        //assign a value to an element attribute to an empty object to remove an eventelement[' on ' + type] =NULL; }                }            },            //Gets the event object in IE with the parameter event object passed into the DOM via window.event to accessGetEvent:function(event) {returnEvent?event:window.event; },            //get the event of the target Dom via Event.target get in IE via event.srcelementGettarget:function(event) {returnEvent.target | |event.srcelement; },            //Cancel the default behavior of an eventPreventdefault:function(event) {if(event.preventdefault) {//Dom MethodEvent.preventdefault (); } Else {                    //Set IE Event.returnvalue = FalseEvent.returnvalue =false; }            },            //Stop event bubblingStoppropagation:function(event) {//Dom Method                if(event.stoppropagation) {event.stoppropagation (); } Else{event.cancelbubble=true;; }            },            //Get related target objectsGetrelatedtarget:function(event) {//Dom method Relatedtarget only contains values for mouseover and mouseout events Otherwise this value is null                if(event.relatedtarget) {returnEvent.relatedtarget; } Else {                    //IE                    if(event.toelement) {returnevent.toelement; } Else {                        if(event.fromelement) {returnevent.fromelement; } Else {                            return NULL; }                    }                }            },            //getting the mouse button 0 means that the left key 1 means that the middle wheel 2 is the right buttonGetbutton:function(event) {//whether DOM mouse events are supported                if(Document.implementation.hasFeature (' mouseevents ', ' 2.0 '))) {                    returnEvent.button; } Else {                    Switch(Event.button) { Case0:                         Case1:                         Case3:                         Case5:                         Case7:                            return0;  Case2:                         Case6:                            return2;  Case4:return1; }                }            },            //Get character encodingGetcharcode:function(event) {if(typeofEvent.charcode = = ' Number ') {                    returnEvent.charcode; } Else {                    returnEvent.keycode; }            }        };

Common event handling Function JS Library

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.