文本输入上的强制数字键盘 [英] Force Number Keyboard on Text Input

查看:49
本文介绍了文本输入上的强制数字键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< 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?

推荐答案

尽管在移动浏览器上尚不能使用(键盘仍为文本),但

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.

这篇关于文本输入上的强制数字键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆