0

我已经制作了一个简单的表单,其中包含一个是和一个否复选框,我想要它,以便当我按下是时它在警报框中显示 5,当我按下否时它显示 0 但目前当我点击提交时它会出现 [警告框中的对象 htmlDivElement]。

<script>

 function alertprice() {            // this will be called on submit of the form
 alert (runningtotal);           // alert the value in variable running total
 }


function totalprice () {                    // function totalprice will set runningtotal depending on boxes ticked
    if(document.getElementById('ramyes').checked) {
        var runningtotal = "5"
            return runningtotal;
}else if(document.getElementById('ramno').checked) {
        var runningtotal = "0"
            return runningtotal;
}
}
          </script>

和html

<form name="theForm" action="shop.html" method="post" onSubmit="checkWholeForm(theForm); return alertprice()">
                <h2>Upgrade RAM to "4GB-Kit GEIL Evo One PC3-12800 DDR3-1600 CL9"?</h2>

        <h3>
            <input type="radio" name="ram" value="yes" id="ramyes">yes<br>
            <input type="radio" name="ram" value="no" id="ramno">no     
        </h3>
4

1 回答 1

2

你必须调用你的函数 totalprice()。例如像这样:

function alertprice(){
    alert(totalprice());
}
于 2013-01-01T17:21:04.567 回答