试图弄清楚如何基于日历年计算值。
$(function () {
"use strict";
var tbl = $('.pcd_disburse');
tbl.find('tr').each(function () {
// $this = this;
$(this).find('input[type=text]').on("change", function () {
calcMileage();
});
});
function calcMileage() {
var rateC = 0.53; // CO mileage rate 2017
var rateB = 0.55; // CO mileage rate 2018
var rateA = 0.58; // CO mileage rate 2019
var getYear = $('.ndate').val();
var year = getYear.slice(-2);
var tbl = $('.pcd_disburse');
tbl.find('tr').each(function () {
var sum = 0;
$(this).find('.ntotal').each(function () {
if (!isNaN(this.value) && this.value.length !== 0 && year === '17') {
sum += parseFloat(this.value * rateC);
} else if (!isNaN(this.value) && this.value.length !== 0 && year === '18') {
sum += parseFloat(this.value * rateB);
} else {
sum += parseFloat(this.value * rateA);
}
});
$(this).find('.miltotal').val('$' + sum.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
});
}
});
计算不正确。目的是计算里程数乘以基于日历年的费率。任何建议表示赞赏!