简体   繁体   English

动态添加输入 - 更新项目数量后的总价格

[英]Dynamic Add Input - Total Price after Update Item Quantity

I need to update automatically the Total amount after changing the quantity of an item.更改商品数量后,我需要自动更新总金额。

I checked this question and also this question, among others but, unfortunately I can't figure out how to get the quantity value of the row and update the Total.我检查了这个问题和这个问题,但不幸的是,我无法弄清楚如何获取行的数量值并更新总计。

I have this code -> https://jsfiddle.net/ricardofranco/gaf32kry/30/我有这个代码-> https://jsfiddle.net/ricardofranco/gaf32kry/30/

My JS我的JS

$('#add_row').click(function() {

    $("#linha").first().clone(true).appendTo("tbody").append("<td data-name='del'><button name='' class='btn btn-danger glyphicon glyphicon-remove row-remove'><span aria-hidden='true' id='row-remove'>-</span></button></td>");

});

$("#linha").on('click', '.row-remove' ,function() {
    $(this).closest("#linha").remove();
});


//sum all values
$('.table-primary').on('input', '.value', function(){

    var totalSum = 0;

    $('.table-primary .value').each(function(){
        var inputValue = $(this).val();

        if(inputValue){

            totalSum += parseFloat(inputValue);
        }

    });

    $('#total').text(totalSum).innerHTML;

});

Can you guys help me on this?你们能帮我解决这个问题吗?

Update the code that sums the amount to multiply the Quantity field.更新将金额相加以乘以 Quantity 字段的代码。

$('.table-primary').on('keyup', '.value', function(){
var totalSum = 0;

$('.table-primary .value').each(function(){
    var inputValue = $(this).maskMoney('unmasked')[0];
    // Get quantity from same row (tr)
    var quantity = $(this).closest('tr').find('.qtd').val() || 0;

    if(inputValue){
        totalSum += (parseFloat(inputValue) * quantity);
    }
});

$('#total').text(totalSum.toFixed(2)).innerHTML;

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM