我有一个< input type ="text"> 元素,我决定使用它代替 type ="number" 以便格式化货币和逗号,并且我想为移动用户使用数字键盘.我发现的现有解决方案要求使用模式="[0-9] *" ,但我也需要一种模式来进行验证.
I have an <input type="text"> element, which I have decided to use instead of type="number" so that I can format currency with commas, and I would like to use the number keyboard for my mobile users. The existing solutions I have found require a pattern="[0-9]*", but I need a pattern for my validation as well.
在此处Codepen .
如何在不更改输入的模式或 type 类型的情况下使用数字键盘?
How can I use the number keyboard without changing the pattern of my input or the type?
推荐答案尽管在移动浏览器上尚不能使用(键盘仍为文本),但我们也许可以使用 inputmode 属性在 text 元素上设置键盘.
Although it doesn't work yet on mobile browsers (keyboard still remains text), we may be able to use the inputmode attribute to set the keyboards on text elements.
我已经完成了一个Codepen的测试(不适用于Android的最新Chrome).也许我们会在不久的将来看到这一点.
I have done up a codepen to test this (not working in latest chrome on Android). Perhaps we will see this implemented in the near future.
更多推荐
文本输入上的强制数字键盘
发布评论