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.