我有一个自动求和单元,当前从0开始。我求和的单元格是输入框,但列表中也有静态框。我想要在自动求和功能中包含静态框,或者创建一个非0的替代起点。这是我当前的代码:
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$('.budget').each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$('.budget').each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#total").html(sum.toFixed(0));
}