簡體   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