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.