The event object for JavaScript

Source: Internet
Author: User

The event object is an object that the DOM provides more detailed information about the event, which is often used when defining event handlers, and in order to ensure that we get an event object that is not NULL, we need to first confirm that:

1 if (!  2     e = window.  Event;

Its commonly used properties are: Event.target (objects that appear as elements, such as anchors, are represented in some browsers with Event.srcelement), Event.which (the key code (Unicode representation) of the keyboard event, often used with String.fromCharCode, is represented in some browsers with Event.keycode), Event.button (the mouse button pressed, the left button is 0 or 1, Right-click 2), Event.altkey, etc.;

In order to be compatible with different browsers, we use properties with different names as follows:

Whichlink = (e.target)? E.target.id:e.srcelement.id;

First determine which one is defined and then used

The event object for JavaScript

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.