JavaScript Gets the event first from a simple example, a simple button control is as follows:<input type= ' button ' name= ' mybtn ' id= ' mybtn ' onclick= ' myFunc () '/>then register the event for it, in this case, how to get the event in JavaScript, especially the Firefox situation. Please see:<script type= ' Text/javascript ' >functionMyFunc () {varEV = Window.event | | Arguments.callee.caller.arguments[0], et= Ev.srcelement | |Ev.target; alert (et.tagname); }</script>no accident, in IE/FF, the above example will output input, which is the name of the tag that triggered the Click event node, IE's event gets here does not say, focus on the situation under the FF.Here's arguments.callee.caller.arguments[0It looks long and strange, why in the case of Firefox, this thing is the event? The first thing you need to know is what Arguments.callee is, and what kind of property is caller? Argments.callee is the function body itself, Arguments.callee.caller is the function body of the call function body Simple example is as follows:<script type= ' Text/javascript ' >functionA () {B ();}functionB () {alert (b===arguments.callee) alert (B.caller===a) alert (Arguments.callee.caller===a)} A ();</script>no accident, the above example will output 3 true, indicating that when a () is called, Function B is related to function A. Well, figure out Arguments.callee and caller, and we'll change the original example to code .<script type= ' Text/javascript ' >functionMyFunc () {alert (arguments.callee.caller.toString ())varEV = Window.event | | Arguments.callee.caller.arguments[0], et= Ev.srcelement | |Ev.target;}</script>we output the function body of the argument.callee.caller to see what the difference is between IE and ff. You can see the output of IE underfunctionAnonymous () {myFunc ()}ff output asfunctiononclick (event) {MyFunc ();} As a result, registering events directly in the HTML control in IEUnder/FF, an anonymous function is defined under IE, and the user-customized function (MYFUNC) is executed internally, while the FF hasdifferent, first FF defines a function with the same name as the node event, here is the onclick event, so it is the function onclick, then the event is passed in as a parameter, Internal re-execution MyFunc. So when the event triggers, in MyFunc, Argument.callee.caller is pointing to the function onclick, of course, argument.callee.caller.arguments[ 0] that is the event.
Get JavaScript under Firefox and IE get event