我正在尝试使表单工作......我有基本代码,我正在修改 orderTotal(最初设置为 0)并根据用户单击的内容添加到它。我希望在没有服务器的情况下使用简单的 vanilla Javascript。
function processOrder() {
orderTotal = 0;
sizeOfPizza();
crustOfPizza();
//displayoutput();
var total = sizeOfPizza();
document.getElementById("orderTotal").value.display
}
//display choice of size of pizza
function sizeOfPizza() {
var size = document.getElementsByName("size");
if (size[0].checked) //if Personal is checked
{
orderTotal += 5.00 //add $5 to the total price
} else if (size[1].checked) //if Medium is checked
{
orderTotal += 8.00 //add $8 to the total price
} else if (size[2].checked) //if Large is checked
{
orderTotal += 10.00 //add $10 to the total price
} else if (size[3].checked) //if Extra Large is checked
{
orderTotal += 12.00 //add $12 to the total price
} else if (size[4].checked) //if Holy Pizza is checked
{
orderTotal += 20.00 //add $20 to the total price
}
}
<h3> Select Size </h3>
<form action="" id="pizza-size">
<input type="radio" name="size" value="Personal"> Personal (4 Slices) <br>
<input type="radio" name="size" value="Medium"> Medium (8 slices)<br>
<input type="radio" name="size" value="Large"> Large (10 slices) <br>
<input type="radio" name="size" value="Extra Large"> Extra Large (12 slices)<br>
<input type="radio" name="size" value="Holy Pizza"> Holy Pizza Batman (24 slices) <br>
</form>
<br>
<input type="button" onclick="processOrder()" value="Preview Order">
<p>Total will appear here: </p>
<p id="orderTotal"> </p>
所以基本上如果用户选择中等披萨我想要 8.00 添加到 orderTotal 并显示......但我不确定如何让它显示(以及确保它正在计算)。
跃然一笑
侃侃尔雅
开心每一天1111
相关分类