我具有下面的表單。使用按鈕,文本字段中的值應該增加或減少。減少按鈕可以正常工作,但增加按鈕只需在數字末尾附加'10',因此100
將變爲10010
,而不是110
。有人可以讓我知道如何解決這個問題嗎?如何添加到文本字段的值
<form name="hello" id="hello">
<table border=0>
<tr>
<td width=200>
<input type=text id="input" style="height: 30px; width: 200px" name=amount value=5>
</td>
<td>
<table border=0>
<tr height=12><td width=20>
<input type=button value="+" style="height: 15px; width: 25px; text-align:center; vertical-align:center; font-size:8px;" onClick="javascript:this.form.amount.value+=10;">
</td></tr>
<tr height=12><td width=20>
<input type=button value="-" style="height: 15px; width: 25px; text-align:center; vertical-align:center; font-size:8px;" onClick="javascript:this.form.amount.value-=10;">
</td></tr>
</table>
</td>
</tr>
</table>
</form>
使用兩個版本的說法,你不希望用戶的輸入被視爲八進制或十六進制。 – Quentin
@昆汀,忘了。謝謝。 – Brandon
注意OP:parseInt的雙參數版本是'parseInt(this.form.amount.value,10)',它表示「我希望這是一個十進制數。」 「parseInt」的第二個參數是符號系統(例如,「10」是十進制的,「16」是十六進制的)。此外,不應將此數字與之後添加的「+ 10」或「-10」混淆。 –