Javascript - returning concatenates instead of sum of variables from input

前端 未结 6 865
南笙
南笙 2021-01-23 07:12

I am trying to get values from input field using .each() and adding them to show the sum in another input value. But unfortunately in spite of using parseInt() I am

6条回答
  •  清酒与你
    2021-01-23 08:03

    Try with parseFloat() on input value

    parseFloat($(this).val()));
    

    var totalvalue = parseInt(0);
    $(document).on("focusout",".value",function() {
        $(".value").each(function() {
            totalvalue = (totalvalue + parseFloat($(this).val()));
        });
        $("#totalvalue").val(totalvalue);
    });
    
    
    

提交回复
热议问题