Take a look at the results of the following code in each browser:
test
IE8: object,object,undefined
FF8. 0: undefined,MouseEvent,undefined
Cr16: MouseEvent,MouseEvent,undefined
Opera: MouseEvent,MouseEvent,undefined
Safira: MouseEvent,MouseEvent,undefined
Other browsers except FF8 All already support window.event
ff8 seems to have an {event:new Event(...)} when calling the event; so you can also use "event" directly in onclick to get the event handle.
Another: A curious student provided a static method QW.EventH.getEvent in QWrap's Event, which is used to obtain the current event object under various circumstances. The code is as follows:
/**
* Get the event object
* @method getEvent
* @param {event} event (Optional)The event object defaults to the event of the host where the calling location is located
* @param {element} element (Optional) Any element object The event of the host where the element object is located
* @return {event} event object
*/
getEvent: function(event, element) {
if (event) {
return event;
} else if (element) {
if (element.document) {return element.document.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) ;
}
},
So, using the QW page, you can write directly like this:
That is: when calling preventDefault, there is no need to pass in the event instance.