我想設置一些數字到<input type="number">
像22,33,44,但在submited我的表單後,值到我的輸入標記是「」,如果我只設置了兩個數字,它就像「22.33」一樣工作,但有3個數字,驗證不通過。我如何設置3個或更多數字並通過驗證?不能設置幾個數字到<input type =「number」>
回答
改爲使用<input type="text" pattern="(\d+)(,\s*\d+)*" />
。
可以工作,但請記住'^'和'$'隱含在模式 –
噢,是的。我會改變這一點。 – shilch
問題是逗號','你有。輸入類型'數字'只佔用數字,用逗號無效,刪除逗號並且應該起作用
如果我刪除逗號,它將只有一個數字,不是嗎? –
是的,你應該採取輸入類型'文本'和解析數字的方法。但我只是爲了更好的可用性而使用多個輸入 –
進入<input type="number">
你只能輸入一個數字,「22.33」仍然是一個數字,但它是小數,而不是一個數字,這是正確的。
如果要插入用逗號(,)分隔的多個數字,則必須使用<input type="text">
,然後解析輸入內容。
是的,這將是個好主意,但我不能使用「文本」類型,它的條件爲這個輸入。 –
您需要使用類型文本並使用正則表達式或字符串操作來執行驗證。 輸入類型=數字用於設置唯一的值,如22或33或44,但不能組合,即「22,33,44」。
所以這是使用「文本」類型的唯一方法?不幸的是我不能使用這種類型,它的條件爲這個輸入。 –
不,這是不可能的,你需要改變類型爲文本和使用模式(猜測不支持IE9)執行驗證,否則JS函數驗證像做字符串。操作 – Bkjain655
- 1. 將值設置爲<input type =「number」/>
- 2. 使用<input type = number>
- 3. <input type =「number」/>沒有在iOS上顯示數字鍵盤
- 4. <input type =「number」>在IE10中不工作
- 5. 爲什麼<input type =「number」maxlength =「3」>在Safari中不工作?
- 6. <input type =「file」/>
- 7. 在<input type =「number」>中禁用文本輸入>
- 8. HTML如何將<input type =「number」>的值設置爲無窮大
- 9. <input type =「submit」/>和<input type =「text」/>
- 10. <input type ='button'/>和<input type ='submit'/>之間的區別
- 11. 如何在<input type =「text」>標籤內放置<input type =「file」>?
- 12. 針對<input type =「number」>的服務器端代碼
- 13. 樣式<input type = number />微調箭頭正確
- 14. HTML中的可編輯單位<input type =「number」>
- 15. 使用AngularJS和Pattern/RegEx驗證<input type =「number」/>
- 16. <input type =「number」/>什麼事件發生變化時觸發?
- 17. <input type ='number'>是自動遞增的。錯誤?
- 18. Grails <field type =「number」...>不工作......?
- 19. <button>與<INPUT TYPE =「圖像」>
- 20. 定製<input type =「file」>?
- 21. 增加<input type =「text」>
- 22. 驗證<input type =「date」>
- 23. 更改<input type =「submit」>
- 24. 爲<input type ='submit'>
- 25. <input type =「text」/>換行
- 26. <type =「input」runat =「server」>
- 27. 清除<input type = file>
- 28. HTML5 <input type =「date」> change
- 29. <input type =「file」> EMPTY
- 30. HTML5 <input type ='range'>
'type =「number」'表示您只能輸入**一個**實際編號 –
如何設置輸入的少數數字?它仍然需要數字輸入。 –