Summary of Event object acquisition methods Test _javascript tips in Google Explorer

Source: Internet
Author: User

Brief introduction:

The event object represents the state of the incident, such as the element in which the event occurred, the state of the keyboard key, the position of the mouse, and the state of the mouse button. Events are usually used in conjunction with functions, and functions are not executed before an event occurs!
Method of getting the event object:

method One:

For example:

Copy Code code as follows:

function Demo1 (e) {

var e = e | | window.event;

This method in IE and Google can not pass the parameter E can also get to the event, but in Firefox must be in the event method to pass events parameter

Before you can get to the event object.

}

<input onclick = "Demo1 (event)" value= "Demo1"/>

Method Two:A common and convenient method (this method is convenient for not passing parameters)

For example:
Copy Code code as follows:

function Demo2 () {

var e = Arguments.callee.caller.arguments[0] | | window.event;

Arguments.callee refers to the current function body.

Arguments.callee.caller is the parent function of the current function

So when executing onclick= "Demo2 ()" Arguments.callee is Demo2 (), Arguments.callee.caller is function onclick,
The first number of onclick is the event, which is arguments.callee.caller.arguments[0.

}

<input onclick= "Demo2 ()" value= "Demo2"/>

Detailed Test Summary:

One: The same way to do everything is to pass the parameter event (the argument must write an event to replace the other name).

Two: Window.event is suitable for IE and Google browser Firefox does not support.

Three: Arguments.callee.caller.arguments[0] only Firefox and Google support, IE does not support this approach.

From the above test results know that Google Browser support for all of the above access, is the most compatible browser.

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.