以前在網頁上要限制只能輸入數字都要 javascript 來輔助,查了一下網上的資料 html5 有提供 <input type="number"> 這簡便的方式來處理,BUT.....實驗之後,發現我又回去找以前的 javascript 來用了。
Input Type: number
The number type is used for input fields that should contain a numeric value.
Use the following attributes to specify restrictions:
max - specifies the maximum value allowed
min - specifies the minimum value allowed
step - specifies the legal number intervals
value - Specifies the default value
我用下面的 sample 試了一下
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.aspx">
Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5">
<input type="submit">
</form>
<p><b>Note:</b> type="number" is not supported in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
當我輸入超過5或是其他英文字,一切如船過水無痕,什麼檢測都沒發生..........
- Mar 04 Tue 2014 11:56
How to allow only numeric (0-9) in HTML5 inputbox
close
全站熱搜
留言列表