只接受整數的數字輸入類型? - Number input type that takes only integers?

問題:

I'm using the jQuery Tools Validator which implements HTML5 validations through jQuery.我正在使用 jQuery 工具驗證器,它通過 jQuery 實現 HTML5 驗證。

It's been working great so far except for one thing.到目前爲止,它一直工作得很好,除了一件事。 In the HTML5 specification, the input type "number" can have both integers and floating-point numbers.在 HTML5 規範中,輸入類型"number"可以同時包含整數和浮點數。

This seems incredibly short-sighted since it will only be a useful validator when your database fields are signed floating-point numbers (for unsigned ints you'll have to fall back to pattern validation and thus lose extra features like the up and down arrows for browsers that support it).這似乎非常短視,因爲當您的數據庫字段是有符號浮點數時,它只會是一個有用的驗證器(對於無符號整數,您將不得不回退到pattern驗證,從而失去額外的功能,例如向上和向下箭頭支持它的瀏覽器)。

Is there another input type or perhaps an attribute that would restrict the input to just unsigned integers ?是否有另一種輸入類型或可能將輸入限制爲無符號整數屬性

I couldn't find any, thanks.沒找到,謝謝

EDIT編輯

Ok, guys, I appreciate your time and help, but I see many undeserved up-voting going on :D.好的,夥計們,我感謝您的時間和幫助,但我看到許多不值得的投票正在進行 :D。

Setting the step to 1 is not the answer since it doesn't restrict the input.將 step 設置爲 1 不是答案,因爲它不限制輸入。 You can still type a negative floating-point number into the textbox.您仍然可以在文本框中鍵入負浮點數。

Also, I am aware of pattern validation (I mentioned it in my original post), but that was not part of the question.另外,我知道模式驗證(我在原帖中提到過),但這不是問題的一部分。

I wanted to know if HTML5 allowed restricting an input of type "number" to positive integer values.我想知道 HTML5 是否允許將“數字”類型的輸入限制爲正整數值。 To this question the answer, it seems, would be "no, it does not".對於這個問題,答案似乎是“不,它沒有”。

I didn't want to use pattern validation because this causes some drawbacks when using jQuery Tools validation, but it now seems that the specification doesn't allow for a cleaner way to do this.我不想使用模式驗證,因爲這在使用jQuery工具驗證時會導致一些缺點,但現在似乎規範不允許使用更簡潔的方法來執行此操作。


解決方案:

參考一: https://stackoom.com/question/axW2
參考二: Number input type that takes only integers?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章