jquery - Explain this fragment of Javascript to me - Stack Overflow

admin2025-04-20  0

I am newbie to jQuery, can someone explain what this code does:

$("#currency form").submit(function(e) {

        triggers.eq(1).overlay().close();
        return e.preventDefault();
    });

I am newbie to jQuery, can someone explain what this code does:

$("#currency form").submit(function(e) {

        triggers.eq(1).overlay().close();
        return e.preventDefault();
    });
Share Improve this question asked Mar 1, 2010 at 16:44 Pentium10Pentium10 208k124 gold badges435 silver badges511 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 12

The first line begins a function that handles the submit event of all form tag(s) in the element with ID currency.
Documentation: Selectors, submit event

The second line closes an overlay in the second element in the triggers variable.
Documentation: eq method, overlay plugin

The third line tries to prevent the submit, but isn't pletely correct. (It should be e.preventDefault(); and/or return false;)
Documentation: event.preventDefault, event handlers

triggers = a jQuery object

triggers.eq(1) = get the second element from the matched elements inside the jquery object

triggers.eq(1).overlay() = get the overlay instance (a plugin) on the second element

triggers.eq(1).overlay().close() = close the overlay.

return e.preventDefault(); = prevent the default action (form submission)

On the submit event of the form, it will:

  1. Get the second element in the triggers collection (of jQuery elements).
  2. Get the overlay on that element.
  3. Close that overlay.
  4. Prevent the submit event from bubbling to the parent handler.
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745112560a285667.html

最新回复(0)