Jquery Plus/Minus Incrementer

后端 未结 10 1198
挽巷
挽巷 2021-01-01 03:53

I want to have a client side Plus / Minus system where a user can click the plus and a value is incremented by 1, minus and the value is decreased by 1, the value should nev

10条回答
  •  执念已碎
    2021-01-01 04:19

    var currentValue = 0;
    
    $(document).ready(function() {
      $('#up').click(function() {
        currentValue++;
      });
      $('#down').click(function() {
        if (currentValue > 0) {
          currentValue--;
        }
      });
    });
    

    Putting currentValue in a textfield or other element would then be trivial.

提交回复
热议问题