Event parameter usage in JavaScript event handlers Introduction _ Basics

Source: Internet
Author: User
In most browsers, when an event handler is triggered, the class instance named event is passed into the processor as the first parameter. IE, which has always been dominant, has acted in its own way, saving the event instance to a global attribute named event.
Copy Code code as follows:

if (!event) event=window.event;

The above statement is used to detect whether the event parameter is undefined or null, and if so, assign the window's event property to it, eliminating browser differences.

To obtain a reference to the target element, use the target attribute in a standard-compatible browser, and use the Srcelement property in IE to handle this inconsistency through object detection
Copy Code code as follows:

var target= (event.target)? Event.target:event.srcElement;

This statement checks for the existence of the event.target definition and, if it exists, assigns its value to the local variable target, otherwise the event.srcelement is assigned to target.
Related Article

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.