问题描述
在我为移动设备设计的网站上,我有一个用于输入 PIN 码的输入字段.我希望文本在输入时被隐藏,并且当移动设备上的用户想要输入 PIN 时,我希望数字键盘弹出.数字键盘在 Type="Number" 时弹出,但在 Type="Password" 时不会弹出,我不能(或不知道如何)设置 Type="Number and Password".
On my site designed for mobile devices I have an input field that is used for PIN numbers. I want the text to be hidden as it is entered and I want the number pad to pop up when the user on the mobile device wants to enter the PIN. The number pad pops up when Type="Number" but not when Type="Password" and I can't (Or don't know how to) set Type="Number and Password".
有什么想法吗?
提前致谢!
推荐答案
某些浏览器 (iOS) 识别特定的 pattern
[0-9]*
的属性值作为触发数字键盘.
Some browsers (iOS) recognize the specific pattern
attribute value of [0-9]*
as triggering numeric keypad.
HTML 5.1 草案包含 inputmode
属性,旨在解决输入模式(如键盘)选择的特定问题,但它有尚未实施.
The HTML 5.1 draft contains the inputmode
attribute, which has been designed to address the specific issue of input mode (like key pad) selection, but it has not been implemented yet.
您可以在将来使用它,尽管当前的 HTML 5.1 出于某些奇怪的原因不允许 type=password
使用它.
You could use it for the future, though – even though the current HTML 5.1 does not allow it for type=password
, for some odd reason.
<input type="password" pattern="[0-9]*" inputmode="numeric">
这篇关于使输入类型=“密码"在移动设备上使用数字键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!