简体   繁体   中英

Shopping Cart Plus Button Consecutively Click

I have a shopping cart, every cart item has plus and minus button. I need when a user click 3 times (consecutively) plus button then call addtocart function after latest click. Latest click mean between first click and third click there is delay time, so user can click 4 times. How can I do ?

why don't try with some counter, each time the user click on the button we sum 1+ to the counter, and when the counter reach 3, we foo something.

here is the jsFiddle

HTML

<input type="button" id="button1" value="Shop" />

JS

var countClick = 0   
    $('#button1').click(function() {
        countClick++
            if(countClick === 3){
               console.log('counter reach ' + countClick)
               var myButton= document.getElementById('button1');
               myButton.style.display ='none';
               setTimeout (function(){
                  myButton.style.display ='inline'; //here we hide the button for 5seconds
               countClick = 0 // here we make the counter go back to 0 again
              },5000);
              //do stuff here like add to cart or something.
             }else{
             console.log('counter still on ' + countClick);
          }
      });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM