Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:58:57
Original
1006 people have browsed it

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.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template