


Introduction to the use of event parameters in JavaScript event processors_Basic knowledge
May 16, 2016 pm 05:33 PMIn 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.
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
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.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

How to use Pygame's Event event module in Python

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

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 Robotaxi reveal to go ahead on October 10 as invitations go out to select shareholders
