文本输入上的强制数字键盘

编程入门 行业动态 更新时间:2024-10-27 10:24:14
本文介绍了文本输入上的强制数字键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

文本输入上的强制数字键盘

本文发布于:2023-11-23 14:53:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   数字键盘

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!