Jquery Plus/Minus Incrementer

后端 未结 10 1153
挽巷
挽巷 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:04

    5
    
    
    
    $('#plus').click(function() { changeValue(1); });
    $('#minus').click(function() { changeValue(-1); });
    
    function changeValue(val) {
        var container = $('#value');
        var current = parseInt(container.html(), 10);
    
        container.html(Math.max(0, current + val).toString());
    }
    

提交回复
热议问题