表單系列之input number總結

clipboard.png

各瀏覽器表現

<input type="number" />

chrome
clipboard.pngweb

除數字字符,只可輸入e和.

IE
clipboard.pngchrome

除數字字符,其餘字符都可輸入,無報錯

Firefox
clipboard.png瀏覽器

除數字字符,其餘字符都可輸入,但會報錯

移除箭頭

//谷歌去除箭頭 
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

//火狐去除箭頭 
input[type="number"] {
    -moz-appearance: textfield;
}

maxlength無效

<input type="number" oninput="if(value.length>5)value=value.slice(0,5)" />

step/min/max

容許小數值app

<input type="number" placeholder="1.0" step="0.01" min="0" max="10">

小知識點

<label for="ticketNum">Number of tickets you would like to buy:</label>
<input id="ticketNum" type="number" name="ticketNum" value="0">

clipboard.png

配合label for,點擊label,就可以讓input獲取焦點。spa

相關文章
相關標籤/搜索