This article mainly introduces the relevant information about the event object in the DOM basic tutorial. For more information, see the events in the browser in the form of objects, similarly, there are also differences between IE and standard dom browsers in obtaining event objects. In IE browser, the event object is a windows object attribute event. the following method is generally used for access.
The code is as follows:
OP. onclick = function (){
Var oEvent = window. event;
}
Although it is a window object attribute, the event object can only be accessed when an event occurs. after all the event processing functions are executed, the object disappears.
The standard dom specifies that the event object must be passed to the event handler as a unique parameter. An Access Event object in a browser similar to Firefox is usually used as a parameter. the code is as follows:
The code is as follows:
OP. onclick = function (oEvent ){
}
Therefore, to be compatible with the two browsers, the following methods are usually used:
The code is as follows:
OP. onclick = function (oEvent ){
If (window. event) oEvent = window. event;
}
After obtaining the Event object, the browser can process various events through a series of its properties and methods, such as mouse events, keyboard events, and browser events. And so on
The following lists common attributes and methods:
We can see from the above that there are some similarities between the two types of browsers. for example, the type attribute is compatible with various browsers. it indicates to get the event type, and the return result is similar to "click ", values such as "mousemove.
This is very useful for a function to process multiple types of events.
As follows: the same function handles multiple events.
The code is as follows: