繁体   English   中英

购物车加号按钮连续点击

[英]Shopping Cart Plus Button Consecutively Click

我有一个购物车,每个购物车项目都有加号和减号按钮。 我需要当用户单击3次(连续)加号按钮,然后在最后一次单击后调用addtocart函数。 最终点击是指第一次点击和第三次点击之间存在延迟时间,因此用户可以点击4次。 我能怎么做 ?

为什么不尝试使用某个计数器,每次用户单击按钮时,我们将1+加到计数器上,而当计数器达到3时,我们将进行foo操作。

这是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);
          }
      });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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