我在C#Razor视图中使用以下jQuery函数:
function calculateTotal(cost, freight, tax) {
var costNum = cost.toString();
costNum = costNum.replace(/,/g, '');
costNum = parseFloat(costNum);
var freightNum = freight.toString();
freightNum = freightNum.replace(/,/g, '');
freightNum = parseFloat(freightNum);
var taxNum = tax.toString();
taxNum = taxNum.replace(/,/g, '');
taxNum = parseFloat(taxNum);
var total = 0;
total = costNum + freightNum + taxNum;
total = numberWithCommas(total);
return total;
}
并从多个地方调用它:
var MonthlyGrandTotal = calculateTotal(totalMonthCost, totalMonthFreight, totalMonthTax);
当我在浏览器中加载页面时,在控制台窗口中看到“未捕获的TypeError:无法读取未定义的属性'toString'”。它似乎并没有真正影响任何东西,但是我很好奇为什么看到错误。