Plus/minus incrementator in Jquery, how to generalize?

前端 未结 4 1516
攒了一身酷
攒了一身酷 2021-01-24 11:52

I\'m using this code

-
   0
+
<         


        
4条回答
  •  猫巷女王i
    2021-01-24 12:26

    try this one if this helps:

    i have changed a little bit i used classes .plus, .minus instead of ids #plus, #minus

     $('.plus').click(function() {
        var sp = parseFloat($(this).prev('span').text());
        $(this).prev('span').text(sp + 1);
     });
    
     $('.minus').click(function() {
        var sp = parseFloat($(this).next('span').text());
        $(this).next('span').text(sp - 1);
     });
    

    check this out in fiddle: http://jsfiddle.net/L2UPw/

提交回复
热议问题