Window. event is now supported by the entire browser, so it will be convenient to use later.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.