jQuery calculate sum of values in all text fields

前端 未结 9 1234
渐次进展
渐次进展 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:24

    $('.price').blur(function () {
        var sum = 0;
        $('.price').each(function() {
    
            if($(this).val()!="")
             {
                sum += parseFloat($(this).val());
             }
    
        });
            alert(sum);
    });​​​​​​​​​
    

    JS Fiddle

提交回复
热议问题