Event object: When an event occurs, the browser automatically creates this object and contains the type of event, mouse coordinates, etc.
Attributes of the event object: Format: event. attribute.
Some instructions:
Event represents the status of the event, such as the element that triggered the event object, the position and status of the mouse, the key pressed, etc.;
The event object is only valid during the event.
The events in Firefox are different from those in IE. The events in IE are global variables and can be used at any time. The events in Firefox need to be guided by parameters and are temporary variables at runtime.
In IE/Opera it is window.event, in Firefox it is event;
The event object is window.event.srcElement in IE, event.target in Firefox, and both are available in Opera.
Binding events
There are usually two methods to bind events to an object (control) in JS:
First define a function in head:
The first method of binding events:
The second method of binding events:
Other examples
Example 1:
Example 2: