Tam*_*ami 164 keyboard android numbers html-input ios
有没有办法强制数字键盘出现在手机上<input type="text">?我刚刚意识到<input type="number">在HTML5中是针对"浮点数",因此它不适用于信用卡号,邮政编码等.
我想模拟数字键盘功能<input type="number">,对于采用浮点数以外的数值的输入.也许还有另一种合适的input类型吗?
Set*_*one 195
你可以做到<input type="text" pattern="\d*">.这将导致出现数字键盘.
有关更多详细信息,请参见此处:适用于iOS的文本,Web和编辑编程指南
<form>
<input type="text" pattern="\d*">
<button type="submit">Submit</button>
</form>Run Code Online (Sandbox Code Playgroud)
Aar*_*ray 134
截至2015年中期,我相信这是最好的解决方案:
<input type="number" pattern="[0-9]*" inputmode="numeric">
Run Code Online (Sandbox Code Playgroud)
这将为您提供Android和iOS上的数字键盘:
它还通过向上/向下箭头按钮和键盘友好的向上/向下箭头键递增来为您提供预期的桌面行为:
在此代码段中尝试:
<form>
<input type="number" pattern="[0-9]*" inputmode="numeric">
<button type="submit">Submit</button>
</form>Run Code Online (Sandbox Code Playgroud)
通过二者结合起来type="number",并pattern="[0-9]*,我们得到的作品无处不在的解决方案.并且,它向前兼容未来的HTML 5.1提议的inputmode属性.
注意:使用模式将触发浏览器的本机表单验证.您可以使用该novalidate属性禁用此功能,也可以使用该属性自定义错误验证的错误消息title.
如果您需要输入前导零,逗号或字母(例如国际邮政编码),请查看此轻微变体.
学分和进一步阅读:
http://www.smashingmagazine.com/2015/05/form-inputs-browser-support-issue/ http://danielfriesen.name/blog/2013/09/19/input-type-number-and-ios-数字键盘/
Gab*_*ias 59
我发现,至少对于类似"密码"的字段,做一些像<input type="tel" />最终生成最真实的数字导向字段的东西,它也有没有自动配置的好处.例如,在我最近为希尔顿开发的移动应用程序中,我最终选择了这个:

......我的客户印象非常深刻.
<form>
<input type="tel" />
<button type="submit">Submit</button>
</form>Run Code Online (Sandbox Code Playgroud)
Ral*_*ine 13
<input type="text" inputmode="numeric">
Run Code Online (Sandbox Code Playgroud)
使用Inputmode,您可以向浏览器提供提示。
小智 13
截至 2020 年
<input type="number" pattern="[0-9]*" inputmode="numeric">
Run Code Online (Sandbox Code Playgroud)
csstricks 写了一篇非常好的文章:https ://css-tricks.com/finger-friend-numeric-inputs-with-inputmode/
小智 8
使用它<input type="text" pattern="\d*">来调出数字键盘存在危险.在firefox和chrome上,模式中包含的正则表达式会导致浏览器验证该表达式的输入.如果与模式不匹配或留空,则会发生错误.请注意其他浏览器中的意外操作.
小智 7
您可以使用inputmodehtml 属性:
<input type="text" inputmode="numeric" />
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请查看有关 inputmode的MDN 文档。
| 归档时间: |
|
| 查看次数: |
208625 次 |
| 最近记录: |