发送数据的方式是
input.functionA发送变量1并运行函数b
input.functionA发送变量2并运行函数b
input.functionA发送变量3并运行函数b
functionB(1)发送变量4并运行函数c
functionB(2)发送变量5并运行函数c
functionB(3)发送变量6并运行函数c
functionC(4,5,6)一次接收一个变量(我认为这是问题,因为它的运行没有收集所有变量)并运行该函数。
非常感谢任何帮助!代码如下! HTML
<form>
<input id="wineQty" class="qty" type="text" placeholder="Wine Tasting Amount" />
<input id="dinnerQty" class="qty" type="text" placeholder="Dinner Amount" />
<input id="golfTeamQty" class="qty" type="text" placeholder="Golf Team Amount" />
</form>
<!--display total cost here-->
The Costs are: <br>
Wine Tasting: <span id="wineCostTag"> </span> <br>
Dinner: <span id="dinnerCostTag"> </span> <br>
Golf Team: <span id="golfCostTag"> </span> <br>
Total Cost: <span id="orderTotalCost"> </span>
的Javascript
var wineCost = 20;
var wineQuantity = document.getElementById("wineQty");
var dinnerCost = 30;
var dinnerQuantity = document.getElementById("dinnerQty");
var golfTeamCost = 400;
var golfTeamQuantity = document.getElementById("golfTeamQty");
var wineCostTag = document.getElementById("wineCostTag");
var dinnerCostTag = document.getElementById("dinnerCostTag");
var golfCostTag = document.getElementById("golfCostTag");
var orderTotalCost = document.getElementById("orderTotalCost");
wineQuantity.oninput = function(){
var val1 = parseInt(wineQuantity.value, 10);
updateWine(val1);
};
dinnerQuantity.oninput = function(){
var val2 = parseInt(dinnerQuantity.value, 10);
updateDinner(val2);
};
golfTeamQuantity.oninput = function(){
var val3 = parseInt(golfTeamQuantity.value, 10);
updateGolf(val3);
};
function updateWine(val1) {
var wineTotalCost = (wineCost * val1);
wineCostTag.innerHTML = wineTotalCost;
updateTotal(wineTotalCost);
}
function updateDinner(val2) {
var dinnerTotalCost = (30 * val2);
dinnerCostTag.innerHTML = dinnerTotalCost;
updateTotal(dinnerTotalCost);
}
function updateGolf(val3) {
var golfTeamTotalCost = (400 * val3);
golfCostTag.innerHTML = golfTeamTotalCost;
updateTotal(golfTeamTotalCost);
}
function updateTotal(wineTotalCost, dinnerTotalCost, golfTeamTotalCost) {
var totalCost = (wineTotalCost + dinnerTotalCost + golfTeamTotalCost);
orderTotalCost.innerHTML = totalCost
}