Introduction to using event parameters in the JavaScript event processor _ basic knowledge

Source: Internet
Author: User
When an Event processor is triggered, the class instance named Event is passed into the processor as the first parameter. The following describes its application in most browsers, when an Event processor is triggered, the class instance named Event is passed into the processor as the first parameter. However, ie, which has been dominant, acts in its own way and saves the Event instance to a global attribute named event.

The Code is as follows:


If (! Event) event = window. event;


The preceding statement is used to check whether the event parameter is undefined or null. If so, assign the event attribute of window to it, thus eliminating browser differences.

To obtain reference of the target element, use the target attribute in a standard compatible browser, and use the srcElement attribute in ie to handle this inconsistency through object detection.

The Code is as follows:


Var targetexample (event.tar get )? Event.tar get: event. srcElement;


Check whether the definition of event.tar get exists. If so, assign the value to the local variable target. Otherwise, assign event. srcElement to the 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.