Jquery, adding new function to the second click

2019-08-05 04:30发布

问题:

I am trying to add new effect after the first click. When submit is clicked for the first time it is working fine. How to make it function after the first click?

  if($('input#submit:not(.clicked)')){
                 $(this).addClass("clicked");
               $('.error').hide().fadeIn(700);
             }  else {
                 $('.error').fadeOut(10000).fadeIn(700);
             }             

回答1:

$('input#sumbit').click(function(){
  if( $(this).hasClass("clicked"))
  {
     $('.error').fadeOut(10000).fadeIn(700); // non-first click effect
  }
  else
  {
     $(this).addClass("clicked");
     $('.error').hide().fadeIn(700); //first click effect
  }
});


回答2:

$('input#submit').bind('click',function(){
    //your function here
    ...


    //and your new click function is here
    $('input#submit').unbind('click').bind('click',function(){
        ...
    })
})