Get JavaScript under Firefox and IE get event

Source: Internet
Author: User

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

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.