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.