in the Tangram group, I thought that standard browsers can only use arguments[0] to obtain the event. As a result, nodiseal classmate It was said that it can be used in this way, so I did the following test"/> in the Tangram group, I thought that standard browsers can only use arguments[0] to obtain the event. As a result, nodiseal classmate It was said that it can be used in this way, so I did the following test">

Home  >  Article  >  Web Front-end  >  window.event is about to be supported by all browsers, and it will be convenient to use in the future_javascript skills

window.event is about to be supported by all browsers, and it will be convenient to use in the future_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:57966browse

Take a look at the results of the following code in each browser:

Copy the code The code is as follows:

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:
Copy code 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:
Copy code The code is as follows:


That is: when calling preventDefault, there is no need to pass in the event instance.
Previous article:Array of chrome native methods_javascript skillsNext article:Array of chrome native methods_javascript skills

Related articles

See more