jQuery calculate sum of values in all text fields

前端 未结 9 1239
渐次进展
渐次进展 2020-11-29 19:52

I have an order form with about 30 text fields that contain numerical values. I\'d like to calculate the sum of all those values on blur.

I know how to select all te

9条回答
  •  借酒劲吻你
    2020-11-29 20:14

    $('.price').blur(function () {
        var sum = 0;
        $('.price').each(function() {
            sum += Number($(this).val());
        });
    
        // here, you have your sum
    });​​​​​​​​​
    

提交回复
热议问题