此javascript代碼無法正常工作(if-else語句).it已輸出,但是當我輸入term = 35時,總是計算on term = 36顯示。有人可以幫我解決這個問題嗎?謝謝!我只是編程方面的新手。此javascript代碼無法正常工作(if-else語句)
<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>
你可以將代碼移到JS上嗎? – 2012-08-09 07:11:40
http://jsfiddle.net – xiaowl 2012-08-09 07:11:54
請格式化代碼,以便我們可以更好地閱讀代碼刪除**''** – Niklas 2012-08-09 07:12:23