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

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

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




        
8条回答
  •  猫巷女王i
    2020-12-14 03:29

    We can use following own function

     (function( $ ){
       $.fn.sum=function () {
        var sum=0;
            $(this).each(function(index, element){
                sum += parseFloat($(element).val());
            });
        return sum;
        }; 
    })( jQuery );
    //Call $('.abcd').sum();
    

    http://www.gleegrid.com/code-snippet/javascript/jquery-sum-input-values-by-class/?filter=bygroup&group=JQuery

提交回复
热议问题