jquery sum of multiple input fields if same class in one input

前端 未结 8 1435
迷失自我
迷失自我 2020-12-14 02:49

Hello I need to sum the values of same class input in one input with class name total.




        
8条回答
  •  悲哀的现实
    2020-12-14 03:26

    You almost had it:

    $(document).on("change", ".qty1", function() {
        var sum = 0;
        $(".qty1").each(function(){
            sum += +$(this).val();
        });
        $(".total").val(sum);
    });
    

    http://jsfiddle.net/DUKL6/1

提交回复
热议问题