我现在想要总计计算...我想要金额字段中所有值的总和...我尝试了该代码,但它不起作用...
$(".amt").each(function(){
total=total+(parseInt($(this).val()))
});
最佳答案
根据以下 HTML:
<table>
<tr>
<td><input class="amt" /></td>
</tr>
<tr>
<td><input class="amt" /></td>
</tr>
</table>
<div id="total"></div>
JS 是:
$('table').focusout(function() {
var sum = 0;
$('.amt').each(function(){
if (this.value != "") {
sum += parseFloat(this.value);
}
});
$('#total').html("Grand total: " + sum);
});
关于javascript - 类标签中所有值的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21454141/