我的老师让我创建一个页面,需要记录您的未结余额,信用卡,以及根据页面上的几个问题,您需要支付本月需要支付的费用。我已经能够看起来正确,我认为我有大部分的Java正确,但当我按下按钮,让一切都认为功能,它不会带回答案。如果有人能帮我弄清楚我做错了什么,以备将来参考,我将非常感激。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
payDue = 0;
questions = {};
var form = document.getElementsByName('questions')[0];
for(var i=0,len=form.length;i<len;i++) {
questions[form[i].name] = form[i];
}
function calcPay(form){
balance= questions.bal.value;
if (questions.ontime.checked == true){
if (questions.mini.checked == true){
payDue=bal/10;
}
else if(questions.spec.checked == true){
payDue=questions.speca.value ;
}
else if(questions.due.checked == true){
payDue=balance ;
}
}
else if (questions.late.checked == true){
if(questions.mini.checked == true){
payDue=bal/10 + 10;
}
else if(questions.spec.checked == true){
payDue=questions.speca.value +10;
}
else if(questions.due.checked == true){
payDue=balance +10;
}
}
return(payDue);
}
</script>
<title>Recreation</title>
</head>
<body>
<form name="questions">
<h1>Calculate Payment</h1>
<p>Enter name: <input type="text" name="name"></p>
<p>Enter credit card number: <input type="text" name="ccn"></p>
<p>Enter balance: <input type="text" name="bal"></p>
<p>Enter Status:</p>
<input type="radio" name="ontime">Ontime<br />
<input type="radio" name="late">Late<br />
<p>Enter payment plan:</p>
<input type="radio" name="mini">Minimum 10%<br />
<input type="radio" name="spec">Specified Amount<br />
<input type="radio" name="due">Amount Due<br />
<p>Specified Amount: <input type="text" name="speca"></p>
<p><input type="button" name="toClick" value="Calculate Your Pay"
onclick="questions.whatsDue.value = calcPay(questions)"></p>
<p><i><b>Your pay is: <input type="text" name="whatsDue"></b></i></p>
</form>
</body>
</html>
答案 0 :(得分:0)
更改
<script type="text/javascript">
payDue = 0;
questions = {};
var form = document.getElementsByName('questions')[0];
for(var i=0,len=form.length;i<len;i++) {
questions[form[i].name] = form[i];
}
function calcPay(form){
到
<script type="text/javascript">
payDue = 0;
function calcPay(questions){