天天看點

開發問題:input type="number"可以輸入字母e

input type=”number” 時隻允許輸入數字,但是字母e可以輸入,原因是e在數學上代表2.71828,是以它也還是一個數字,是以能輸進去。

解決辦法為在input屬性上加上:解決辦法為在input屬性上加上:

onKeypress=”return (/[\d]/.test(String.fromCharCode(event.keyCode)))”

開發問題:input type="number"可以輸入字母e

其中min max是設定可輸入的最小值和最大值。如果想要限制輸入不能為負數和0,可以設定min=”1” 。

繼續閱讀