如何使用jquery计算倍数的总计

如何使用jquery计算倍数的总计,jquery,Jquery,这是我的脚本如何从多个值计算总计,我正在使用带有自动完成表单的表添加删除行 我的剧本: (function() { "use strict"; $("table").on("change", "input", function() { var row = $(this).closest("tr"); var qty = parseFloat(row.find(".quantity").val()); var price = par

这是我的脚本如何从多个值计算总计,我正在使用带有自动完成表单的表添加删除行

我的剧本:

(function() {
    "use strict";

    $("table").on("change", "input", function() {
        var row = $(this).closest("tr");
        var qty = parseFloat(row.find(".quantity").val());
        var price = parseFloat(row.find(".productprice").val());
        var tcost = qty * price;
        row.find(".tcost").val(isNaN(tcost) ? "" : tcost);


    });
    if (!isNaN(tcost))
        total += tcost;
    $("#total").html("EUR " + total);
    row.find(".total").val(isNaN(total) ? "" : total);
})();

这应该让你开始:

$select.changefunction{ 变量数量=$this.val

// get the price cell by moving up a level and searching for
// the descendant with a class name beginning with `price'.
// Remove the dollar sign to do math
var price = $(this).closest("tr")
                   .find("td[class^=price]")
                   .html().split("$")[1];

// a quantity is a whole number but a price is a float
var total = parseInt(qty) * parseFloat(price);

// write the total for this book to the 'total' cell
$(this).closest("tr")
       .find("td[class^=total]")
       .html("$" + total);

// sum up all the totals
var grandTotal = 0;
$("td[class^=total]").each(function() {
    grandTotal += parseFloat($(this).html().split("$")[1]); 
});

// update the grandtotal cell to the new total
$(".grandtotal").html("$" + grandTotal);
});​

换句话说,您需要:

1-从所选选项的值中获取数量

2-从同一行中以“price”开头的单元格中获取价格,将其乘以数量,并更新同一行的“total”单元格

3-重新计算总计-所有总计的总和,并将该值放入.grandtotal单元格


试试这里:

你的问题是什么?