ATM Javascript问题

ATM Javascript问题,javascript,jquery,html,Javascript,Jquery,Html,我需要修复这个代码,当按下“取款”按钮时,我需要在选择金额后单击“取款”按钮时取款,而不是在按下“取款”按钮时取款 请帮忙。多谢各位 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>

我需要修复这个代码,当按下“取款”按钮时,我需要在选择金额后单击“取款”按钮时取款,而不是在按下“取款”按钮时取款

请帮忙。多谢各位

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title> ATM Model 170-JavaScript Assignment 7: Valarie Salas</title>
</head>
<body>
    <h1>Welcome!</h1>
    <table>
        <tr>
            <td><input type="button" value="$20" onclick='withdraw(20)'/></td>
            <td></td>
            <td></td>
            <td><input type="button" value="Withdrawal" onclick='withdrawamount+'/></td>
        </tr>
        <tr>
            <td><input type="button" value="$60" onclick='withdraw(60)'/></td>
            <td>Current Balance</td>
            <td><input type="text" name="Current Balance" value="5000.00" id="textField1" onchange=''/></td>
            <td></td>
        </tr>
    <tr>
        <td><input type="button" value="$100" onclick='withdraw(100)'/></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td><input type="button" value="Other Amount" onclick='alert("Sorry.  This Function Is Not Available.")'/></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </table>

    <script type="text/javascript">

        alert("Please select the amount you would like to withdraw.")
        var balance=5000;

        function withdraw(amount)
        {
            var sure = confirm("Are you sure you want to withdraw $"+amount+" from this account?");
            if(sure == true)
            {
            balance = balance - amount;
            document.getElementById("textField1").value = balance;
            }else
            {
            alert("No withdrawal made");
            }
            alert("Your balance is "+balance);
        }



    </script>
</body>
</html>

ATM机型7:Valarie Salas
欢迎
经常项目差额
提醒(“请选择您要提取的金额。”)
var余额=5000;
功能提取(金额)
{
var sure=confirm(“您确定要从此帐户中提取$”+金额+”);
如果(确定==true)
{
余额=余额-金额;
document.getElementById(“textField1”)。值=余额;
}否则
{
警惕(“未撤回”);
}
警惕(“您的余额为”+余额);
}
从您对Dogoku的报价中

我真的很想学习Javascript。我只是想寻求一些建议 还有指引我正确方向的指针

我能建议的是,如果你没有在20、60和100上使用按钮,而是把它们做成单选按钮,带有Id

因此,您可以让用户选择他们希望提取的金额,然后单击提取按钮。当他们这样做时,检查哪个单选按钮被选中,这可以通过document.getElementById('nameOfYourRadioBtn')完成

这应该能帮你走。 (还要记住设置一个条件,确保用户在任何时候都不能选择多个单选按钮)

希望这将为你指明正确的方向。享受编码:)


库什

你试过什么?不要指望我们为你做功课,甚至不亲自动手。我试图弄明白如何使用全局变量,但我不明白它们是如何工作的,它适合我的程序。我以为我可以将变量设置为按钮值,但我做不到。公平地说,等一下。。。顺便说一句,你的html写错了。我会更新你的问题来解决这个问题,相信我,我不想让你做我的家庭作业。我真的很想学习Javascript。我只是在寻找一些建议和指点来指引我正确的方向。谢谢你的建议,库什!如果在我的作业上没有按钮是“必须”的,你的建议会有很大的帮助。你确实需要使用一个变量。如果我们说得更多,我们会帮你作弊。库什的回答是一个很好的建议。它们看起来像按钮并不意味着它们不能像单选按钮一样。迪福同意克里斯的观点,这只是javascript有多强大,但另一种选择是,创建一个javascript对象,该对象具有一个名为“DruminalAmount”的属性,并在用户每次单击DruminalAmount按钮时为该属性赋值,然后在您的draw函数中调用js对象和您指定的属性,并使用该值!谢谢我试试看会发生什么