Home Web Front-end JS Tutorial Introduction to the use of event parameters in JavaScript event processors_Basic knowledge

Introduction to the use of event parameters in JavaScript event processors_Basic knowledge

May 16, 2016 pm 05:33 PM
event event handler

In most browsers, when an event handler is triggered, an instance of the class named Event is passed into the handler as the first parameter. However, Internet Explorer, which has always been in the mainstream, behaves in its own way and saves the Event instance in a global attribute called event.

Copy code The code is as follows:

if (!event) event=window.event;

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

To obtain a reference to the target element, use the target attribute in standards-compliant browsers and the srcElement attribute in IE to handle this inconsistency through object detection
Copy code The code is as follows:

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

This statement checks whether the definition of event.target exists. If it exists, assign its value to the local variable target; otherwise, assign event.srcElement to target.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Event processing library in PHP8.0: Event Event processing library in PHP8.0: Event May 14, 2023 pm 05:40 PM

Event processing library in PHP8.0: Event

Steam Summer Sale - Valve teases 95% off AAA games, confirms discounts for viral games Palworld and Content Warning Steam Summer Sale - Valve teases 95% off AAA games, confirms discounts for viral games Palworld and Content Warning Jun 26, 2024 pm 03:40 PM

Steam Summer Sale - Valve teases 95% off AAA games, confirms discounts for viral games Palworld and Content Warning

How to use Pygame's Event event module in Python How to use Pygame's Event event module in Python May 18, 2023 am 11:58 AM

How to use Pygame's Event event module in Python

Event handlers and modifiers in Vue 3 to optimize user interaction experience Event handlers and modifiers in Vue 3 to optimize user interaction experience Sep 08, 2023 am 11:00 AM

Event handlers and modifiers in Vue 3 to optimize user interaction experience

Steam Summer Sale trailer teases 95% off AAA game deals, confirms price cuts for Palworld, Stellaris, Content Warning Steam Summer Sale trailer teases 95% off AAA game deals, confirms price cuts for Palworld, Stellaris, Content Warning Jun 26, 2024 am 06:30 AM

Steam Summer Sale trailer teases 95% off AAA game deals, confirms price cuts for Palworld, Stellaris, Content Warning

In JavaScript, when the browser window is resized, which event is this? In JavaScript, when the browser window is resized, which event is this? Sep 05, 2023 am 11:25 AM

In JavaScript, when the browser window is resized, which event is this?

Tesla sends out Robotaxi invitations for October 10 autonomous driving demo event in LA Tesla sends out Robotaxi invitations for October 10 autonomous driving demo event in LA Sep 27, 2024 am 06:20 AM

Tesla sends out Robotaxi invitations for October 10 autonomous driving demo event in LA

Tesla Robotaxi reveal to go ahead on October 10 as invitations go out to select shareholders Tesla Robotaxi reveal to go ahead on October 10 as invitations go out to select shareholders Sep 26, 2024 pm 06:06 PM

Tesla Robotaxi reveal to go ahead on October 10 as invitations go out to select shareholders

See all articles