javascript - 以密码输入类型在手机上显示数字键盘
问题描述
我要实现
<input type="password">
仅在移动设备 (iOS/Android) 上显示数字键盘。
我见过这样的解决方案:
input[type=number] {
-webkit-text-security: disc;
}
但由于安全性和可访问性,我不能使用它。输入值将在检查器中可见,并且语音会大声读出数字。
有没有办法通过数字键盘和适当的可访问性实现隐藏输入?
解决方案
尝试这个...<input type="password" pattern="[0-9]*" inputmode="numeric">
更新答案:
多花几分钟思考一下。我已经得到它(并经过测试)。
/* Requires discs as characters */
input[type="number"] {
-webkit-text-security: disc !important;
}
/* Removes Spin Button */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
<div style="text-align: center;">
<label for="pin" class="my-1 mr-2 strong">Password</label>
<input class="form-control pin" id="pin" type="number" inputmode="numeric" autocomplete="off">
</div>
推荐阅读
- sqlite - 每次滚动时都会调用 Recyclerview 中的方法
- python - 如何检查列表中是否存在字符序列?
- node.js - UnhandledPromiseRejectionWarning: ReferenceError: adb is not defined
- javafx - 如何在 VBox 中过滤和显示
- javascript - 如何进行不区分大小写的搜索?
- java - spring java项目中的import org问题
- angular - 如何更新文件输入字段的值
- django - 运行 WSGI 应用程序时出错,ImportError: No module named 'mysite' during hosting on pythonanywhere
- charts - 谷歌表格数组 - 填补不规则数据的空白
- git - 将 git 日志日期格式保存在 .gitconfig 中