javascript - Passing 'event' into the function as an argument -


I'm a newbie with both JS and jQuery, and I'm a bit confused about what conditions you have to pass Event as an argument in the function, and in what situation you not will be required. For example:

  $ (document) .ready (function () {$ ('# foo'). Click (function () {// something Please}};});  

vs

  $ (document) .ready (function () {$ ('# foo'). Click (Tasks) / do something });        }); There are some uses in the    

event logic you only assign it to your handler There is a need to specify in the form of an argument if you are actually going to use it - Javascript handles the number of arguments without any complaints.

The most common use you will see is to prevent the default behavior of the action that triggers an event:

  $ ('a.fake'). Click (function (e) {e.preventDefault (); Warning ("This is a fake link!");});  

... In fact, clicking on your href will close any link with class duplicate Similarly, You can cancel form submissions with it, e.g. In verification methods it is as return false , but more reliable.

The jQuery event object is actually a cross-browser version available in standard event argument everything but IE This is essentially a shortcut, which lets you use only one code path instead of viewing the browser used in every event handler.

(If you read non-jQuery code then you will see a lot of the following, which is done to work around the lack of IE.

  function (E) {e = e || window.event; // for IE  

This is a pain, and it is very easy to deal with libraries.)

Essentially, include it if you are looking at anything there, and otherwise do not worry, I would like to include it always, not only that, In the must remember never to join if I need to decide whether to go all the above.


Comments