Registering jQuery click, first and second click

前端 未结 9 882
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 23:23

Is there a way to run two functions similar to this:

$(\'.myClass\').click(
    function() {
        // First click
    },
    function() {
        // Second         


        
相关标签:
9条回答
  • 2020-11-30 00:04

    Or this :

    var clicks = 0;
    
    $('.myClass').click(function() {
        if (clicks == 0){
            // first click
        } else{
            // second click
        }
        ++clicks;
    });
    
    0 讨论(0)
  • 2020-11-30 00:08
    When You click the selector it automatically triggers second and waiting for another click event.
    
    $(selector).click(function(e){
        e.preventDefault(); // prevent from Posting or page loading
         //do your stuff for first click;
         $(this).click(function(e){
         e.preventDefault();// prevent from Posting or page loading
          // do your stuff for second click;
         });
    });
    

    I hope this was helpful to you..

    0 讨论(0)
  • 2020-11-30 00:13
                var click_s=0;
                $('#show_pass').click(function(){
                    if(click_s % 2 == 0){
                        $('#pwd').attr('type','text');
                        $(this).html('Hide');
                    }
                    else{
                        $('#pwd').attr('type','password');
                        $(this).html('Show');
                    }
                    click_s++;
                });
    
    0 讨论(0)
提交回复
热议问题