📜  javascript 求和表行值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:23.943000             🧑  作者: Mango

代码示例1
$(function() {
  $("#subtotal").html(sumColumn(4));
  $("#total").html(sumColumn(5));
});

function sumColumn(index) {
  var total = 0;
  $("td:nth-child(" + index + ")").each(function() {
    total += parseInt($(this).text(), 10) || 0;
  });  
  return total;
}

ClientName ItemName Quantity 12 34
ClientName ItemName Quantity 56 78
ClientName ItemName Quantity 90 12
Totals