有人可以指出我的错误。我一直以nan
作为输出。
function order() {
var name = document.getElementById("name");
var numOfCakeDonuts = document.getElementById("numOfCakeDonuts").valueAsNumber;
var numOfGlazedDonuts = document.getElementById("numOfCakeDonuts").valueAsNumber;
var time = document.getElementById("time").valueAsNumber;
const taxrate = 0.14;
const donutPrice = 0.50;
var subTotal = (numOfCakeDonuts + numOfGlazedDonuts) * donutPrice;
var tax = subTotal * taxrate;
var total = subTotal + tax;
document.getElementById("sub").value = subTotal.toFixed(3);
document.getElementById("tax").value = tax.toFixed(3);
document.getElementById("total").value = total.toFixed(3);
}
答案 0 :(得分:1)
您的变量numOfGlazedDonuts
正在为valueAsNumber
元素分配id=numOfCakeDonuts
作为开头。