我正在尝试使用5个按钮($ 20,$ 60,$ 100,其他金额和提款)创建一个简单的ATM程序。我需要在按下金钱按钮时创建一个确认框,并在按下撤销按钮时从文本框中扣除金额。这是我的代码:
<form action="" >
<table>
<tr>
<td>
<input type="button" value="$20" onclick='accept())'/>
</td>
<td>
</td>
<td>
</td>
<td>
<input type="button" value="Withdrawal" onclick=''/>
</td>
</tr>
<tr>
<td>
<input type="button" value="$60" onclick='accept()'/>
</td>
<td>Current Balance
</td>
<td>
<input type="Current Balance" value="5000.00" onchange=''/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="button" value="$100" onclick='accept()'/>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="button" value="Other Amount" onclick=''/>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var balance=50000;
function withdraw(amount)
{
var sure = confirm("Are You Sure You Want To Withdraw This Amount?");
if(true)
{
balance = balance - amount;
}else
{
alert("No Withdrawal Made");
}
alert("Your Balance Is "+balance);
function
</script>
请帮忙!这真让我抓狂。谢谢!
答案 0 :(得分:0)
我没有清楚地得到问题,但我认为您需要确认您的ATM应用程序的“其他金额”按钮的金额。你假设使用“提示”,使用它就像一个警告框。
<input type="button" value="Get" onclick="prompt('How Much Amount, you want to withdraw?')">
您的代码可以是某种东西,如上所示。
答案 1 :(得分:0)
好让我们看看一些问题;
<form action="" >
<table>
<tr>
<td>
<input type="button" value="$20" onclick='accept())'/> // you have an extra closing brace here
</td>
<td>
</td>
<td>
</td>
<td>
<input type="button" value="Withdrawal" onclick=''/>
</td>
</tr>
<tr>
<td>
<input type="button" value="$60" onclick='accept()'/>
</td>
<td>Current Balance
</td>
<td>
<input type="Current Balance" value="5000.00" onchange=''/> //Current balance is not a valid type
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="button" value="$100" onclick='accept()'/>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="button" value="Other Amount" onclick=''/>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<script type="text/javascript">
var balance=50000;
function withdraw(amount) //this function should be called accept not withdraw
{ //you didn't close this brace
var sure = confirm("Are You Sure You Want To Withdraw This Amount?");
if(true) //should be if (sure)
{
balance = balance - amount;
}else{
alert("No Withdrawal Made");
}
alert("Your Balance Is "+balance);
function //this shouldn't be here
</script>