function convert2Int(num) {
num = parseInt(num);
return isNaN(num) ? 0 : num;
}
$(function () {
var rows = $("#saleTable tr").length - 1;
var columns = $("#saleTable tr td").length / rows;
//alert($("#saleTable tr:eq(2) td:eq(0)").html());
for (var j = 0; j < columns; j++) {
var tempResult = 0;
for (var i = 1; i <
rows; i++) {
// alert($("#saleTable
tr:eq(" + i + ") td:eq(" + j + ")").html());
tempResult += convert2Int($("#saleTable tr:eq(" + i + ") td:eq(" + j +
")").html());
}
$("#saleTable tr:eq(" + rows + ") td:eq(" + j + ")").html(tempResult);
}
});
原文地址:http://www.cnblogs.com/kevin1988/p/3709453.html