Switch function

My question is that two functions are passed in to switch why .. and outside of another function there is something that also confuses plz tell me

 $('#login a').toggle(function() {
    $(this)
      .addClass('active')
      .next('form')
      .animate({'height':'show'}, {
        duration:'slow',
        easing: 'easeOutBounce'
      });
  }, function() {
    $(this)
      .removeClass('active')
      .next('form')
      .slideUp();
  });
  $('#login form :submit').click(function() {
    $(this)
      .parent()
      .prev('a')
      .click();
  });
+3
source share
2 answers

The toggle () method takes two (or more) functions as arguments and calls one of them in turn each time an element is clicked.

Functions of first-class citizens in Javascript: you can manipulate them like any other object, including passing them to other functions:

function foo(otherfunction)
{
    otherfunction();
}

function bar()
{
    window.alert("bar() was called.");
}

foo(bar);  // Ultimately calls `bar()`.
+1
source

According to the JQuery API Documentation, functions will be called when the clicks alternate:

  • - ,
  • - ,
  • - ,
  • - ...

, anchor (a), , , . :

<a href="#">click will be simulated for this link</a>  
<div>  
    <input type="submit"/>  
</div>
0

Source: https://habr.com/ru/post/1779382/


All Articles