Two methods for obtaining event in firefox and ie _ javascript skills

Source: Internet
Author: User
Some colleagues often ask me how to obtain the event in Firefox. Most of them want to get the event. the keyCode function. Next we will introduce you to the two implementation methods. If you need to know how to get the event in Firefox, you can refer to some colleagues who often ask me how to get the event. Most of them want to get the event. two keyCode Functions
Method 1:

The Code is as follows:


Function a (e ){
E = e | window. event;
Alert (e. keyCode );
}


Use IE

The Code is as follows:




Firefoxfirefox is called as follows

The Code is as follows:




In this way, the call is successful.
This method requires a parameter in firefox, which is not very good. The second method is described below.
Method 2:

The Code is as follows:


Function (){
E = arguments. callee. caller. arguments [0] | window. event;
Alert (e. keyCode );
}


Both ie and firefox are called as follows:

The Code is as follows:




Here I want to explain arguments. callee. caller. arguments [0],
A simple example is as follows:

The Code is as follows:


Function (){
B ();
}
Function B (){
Alert (B === arguments. callee)
Alert (B. caller =)
Alert (arguments. callee. caller =)
}
A ();


The preceding example outputs three true values, indicating the relationship between function B and function a when a () is called.
Arguments. callee refers to the current function body.
Arguments. callee. caller is the upper-level function of the current function.
Therefore, when onclick = "a ()" is executed, arguments. callee is a (), and arguments. callee. caller is function onclick.
The first number of functions in onclick is event, that is, arguments. callee. caller. arguments [0.
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.