只接受整数的数字输入类型? - 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?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章