我正在使用此代码进行计算:
$('#outfitters').submit(function(event) {
var days = $('#days').val();
var final_price = 0;
var length = parseFloat($("#length").val());
var material = parseFloat($("#material").val());
var fibre = parseFloat($("#fibre").val());
var kevlar = parseFloat($("#kevlar").val());
final_price = parseFloat(days * (length + material + fibre + kevlar));
console.log(length);
alert("Final Price is: " + final_price);
window.location.reload(true);
});
所有值都从如下所示的 JSON 中检索,
{
"company":"SS",
"locations":[
{ "name":"Kincardine" },
{ "name":"Killarney"},
{ "name":"Bon Echo"}
],
"twelve": 25.00,
"fourteen": 30.00,
"sixteen":35.00,
"paddles": 10.00,
"lifevest": 10.00,
"fibreglass":0.00,
"kevlar": 10.00
}
问题是我在计算 final_price 时得到了 NaN,尽管我完美地检索了所有值。我在这里缺少什么吗?