如图,计算 Total 的和,用 JQuery 实现如下:
<input class="form-control total" name="total-1">
<input class="form-control total" name="total-2">
<input class="form-control total" name="total-3">
//JQuery 遍历同一组 class 的 input 的值求和
function totalSum(){
let sum = 0;
$(".total").each(function(){
total = Number($(this).val());
sum = sum + total;
});
//console.log(sum);
return sum;
}