我有一个函数来汇总html表中的一列数据.它确实令人钦佩,我只想把它放在那里,需要将数千个分开.最初,您会注意到,添加的数字中有逗号.因此该函数将添加它们,它们将被删除.如何在那里添加逗号?
<script type="text/javascript">
function sumOfColumns(tableID, columnIndex, hasHeader) {
var tot = 0;
$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
.children("td:nth-child(" + columnIndex + ")")
.each(function() {
tot += parseInt($(this).html().replace(',', ''));
});
return "Total Pounds Entered : " + tot;
}
</script>
Run Code Online (Sandbox Code Playgroud) jquery ×1