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.