好吧,这就是我作业的javascript部分的任务。
Javascript函数将:
以下是您编程所需的信息:
继承我的代码,我无法获得我已经尝试了几个小时的javascript部分。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function first(drink, shots, customer) {
var x = customer.value;
if (x == '' || x == 'null') {
alert("Yo enter a name.");
}
else {
if (drink == "0") {
price = 3;
} else if (drink == "1") {
price = 2;
} else if (drink == "2") {
price = 2.50;
} else {
price = 1.50;
}
if(shots > 0) {
Price= price + (shots * 0.5)
} else {
alert ("Thank you");
}
}
}
</script>
</head>
<body>
<form>
<h1>Javascript calculating Function: Calculate the cost of a coffee drinks using Javascript.</h1>
<p>What would you like to order?</p>
<select id="drink">
<option value="0" id="0">Latte</option>
<option value="1" id="1">Americano</option>
<option value="2" id="2">Cappuccino</option>
<option value="3" id="3">Drip Coffee</option>
</select>
<br>
<br>
<select id="shots">
<option value="0" id="0">No Extra</option>
<option value="1" id="1">1</option>
<option value="2" id="2">2</option>
<option value="3" id="3">3</option>
<option value="4" id="4">4</option>
</select>
<br>
<br>
<p>Enter name here:</p>
<input id="customer" value="customer" type="text"/>
<br>
<br>
<button onclick="first(drink, shots, customer)">Complete Order</button>
</form>
</body>
</html>
任何帮助都表示感谢,提前谢谢!
答案 0 :(得分:0)
您需要从输入字段中获取first()
的参数。
<button onclick="first(document.getElementById('drink').value, document.getElementById('shots').value, document.getElementById('customer'))">Complete Order</button>
答案 1 :(得分:0)
试试这个
<h1>Javascript calculating Function: Calculate the cost of a coffee drinks using Javascript.</h1>
您想订购什么?
<option value="0" id="0">Latte</option>
<option value="1" id="1">Americano</option>
<option value="2" id="2">Cappuccino</option>
<option value="3" id="3">Drip Coffee</option>
<option value="0" id="0">No Extra</option>
<option value="1" id="1">1</option>
<option value="2" id="2">2</option>
<option value="3" id="3">3</option>
<option value="4" id="4">4</option>
在此输入姓名:
<button id='submit'>Complete Order</button>
<script>
$("#submit").click(function ()
{
var drink = $("#drink").val();
var shots = $("#shots").val();
var customer = $("#customer").val();
var x = customer;
if (x == '' || x == 'null')
{
alert("Yo enter a name.");
}
else
{
if (drink == "0") { price = 3; }
else if (drink == "1") { price = 2; }
else if (drink == "2") { price = 2.50; }
else { price = 1.50; }
if(shots > 0)
{
price= price + (shots * 0.5)
}
alert ("Your Order Total is : "+price+" \nThank you");
}
});
</script>