这个 javascript 代码不能正常工作(if-else 语句)。它有输出,但是当我输入 term=35 时,总是显示 term=36 的计算。有人可以帮我解决这个问题吗?谢谢!我只是编程的新手。
<script language="javascript" type="text/javascript">
function calc1(form) {
var principal = form.principal.value;
var term = form.term.value;
var paidup = form.paidup.value;
var unearn = form.unearn.value;
form.paidup.value = form.principal.value * 0.01;
if (principal >= 50000, term = 36) {
form.unearn.value = principal * .27750;
}
else if (principal >= 50000, term = 35) {
form.unearn.value = principal * .27000;
}
}
</script>
<FORM>
<table>
<tr>
<td>Enter Principal Amount:</td>
<td><INPUT TYPE ="text" NAME="principal" SIZE=15 ></td>
</tr>
<tr>
<td>Enter Number of Term:</td>
<td><INPUT TYPE ="text" NAME="term" SIZE=15 ></td>
</tr>
<tr> <td><INPUT TYPE ="button" VALUE="Calculate" ONCLICK="calc1(this.form)"></td><td></td> </tr>
</tr> <tr> <td>Paid-Up Share Capital:</td> <td><INPUT TYPE="text" NAME="paidup" SIZE=4 ></td> </tr> <tr> <td>Unearned Income:</td> <td><INPUT TYPE="text" NAME="unearn" SIZE=4 ></td> </tr>
</table>
</form>