自动计算总价值 [英] auto calculate total value
本文介绍了自动计算总价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格如图所示
我需要的是,当我输入/更改金额值时,它会自动计算底部的金额
what i need is, when i type/ change value in amount, it auto calculate sum at the bottom
我也不想让任何角色添加......
also i don't want to let add any character...
谢谢
推荐答案
在每个金额输入字段中添加 class =calc
并添加 id =total
到您的总结果元素。
Add class="calc"
to each of your amount input fields and add id="total"
to your total result element.
jQuery代码:
$(document).ready(function(){
$('.calc').change(function(){
var total = 0;
$('.calc').each(function(){
if($(this).val() != '')
{
total += parseInt($(this).val());
}
});
$('#total').html(total);
});
})(jQuery);
和示例HTML代码:
<input type="text" class="calc" value="">
<input type="text" class="calc" value="">
<input type="text" class="calc" value="">
<input type="text" class="calc" value="">
<input type="text" class="calc" value="">
<span id="total"></span>
希望有所帮助;)
这篇关于自动计算总价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文