0
我无法弄清楚为什么在点击“计算支付”后,显示为NaN
。我认为这可能发生的唯一原因是因为computeMonthlyPayment()
函数,更具体地说是计算线。我也认为它可能与单选按钮有关。显示NaN的文本框,以及基本计算问题
<!DOCTYPE html>
<html>
<head>
\t <title> Monthly Payment Calculator</title>
</head>
<script>
\t function computeMonthlyPmt(){
\t \t var amt = document.MonthlyPmt.LoanAmt.value;
\t \t var r = document.MonthlyPmt.Rate.value;
\t \t var t = document.MonthlyPmt.Year.value;
\t \t document.MonthlyPmt.Payment.value = (amt*(r/12))/(1-Math.pow(1+(r/12),-12*t));
\t \t
\t }
</script>
<body>
<h1> Monthly Payment Calculator </h1>
<form name="MonthlyPmt">
\t <p> Enter Loan:<input type="text" name="LoanAmt" value="" /> </p>
\t
\t \t
\t <p> Select Rate: </p>
\t <select name="Rate">
\t \t <option value=0.04>4%</option>
\t \t <option value=0.045>4.5%</option>
\t \t <option value=0.05>5%</option>
\t \t <option value=0.055>5.5%</option>
\t \t <option value=0.06>6%</option>
\t </select>
\t <p> Select Term: </p>
\t \t <input type="radio" name="Year" value=10/>10 Years<br>
\t \t <input type="radio" name="Year" value=15/>15 Years<br>
\t \t <input type="radio" name="Year" value=30/>30 Years<br>
\t <p> Monthly Payment: </p>
\t \t <input type="text" name="Payment" value="" /><br>
\t \t <input type="button" value="Compute Payment" name="btnCompute" onclick="computeMonthlyPmt()" />
</form>
</body>
</html>
谢谢您的回答,但即使改变这种后,我仍然得到同样的问题。 –
那么你把所有的值都包含在引号中? – epascarello
这是正确的 –