Check the following code in different browsers:
Copy codeThe Code is as follows: <body onclick = "alert ([window. event, event, this. event]);"> test </body>
IE8: object, object, undefined
FF8.0: undefined, MouseEvent, undefined
Cr16: MouseEvent, MouseEvent, undefined
Opera: MouseEvent, MouseEvent, undefined
Safira: MouseEvent, MouseEvent, undefined
All browsers except FF8 support window. event.
Ff8 seems to contain a {event: new Event (...)} When calling an event. Therefore, you can use "event" to obtain the Event handle in onclick.
In addition, curious provides a static QW. EventH. getEvent method in QWrap Event to obtain the current Event object in various situations. The Code is as follows:Copy codeThe Code is as follows :/**
* Get the event object
* @ Method getEvent
* @ Param {event} event (Optional) the event object is the event of the host where the call location is located by default.
* @ Param {element} element (Optional) event of the host where the element object of any element object is located
* @ Return {event} event object
*/
GetEvent: function (event, element ){
If (event ){
Return event;
} Else if (element ){
If (element.doc ument) {return element.doc ument. parentWindow. event ;}
If (element. parentWindow) {return element. parentWindow. event ;}
}
If (window. event ){
Return window. event;
} Else {
Var f = arguments. callee;
Do {
If (/Event/. test (f. arguments [0]) {return f. arguments [0];}
} While (f = f. caller );
}
},
Therefore, the QW page can be written as follows:Copy codeThe Code is as follows: <a href = "#" onclick = "EventH. preventDefault ()"> vertex I am invalid </div>
That is, when preventDefault is called, the event instance is not required.