我知道这个:
<input type="tel">
我知道这一点:
<input type="password">
但是我想同时使用这两个功能。我希望在iOS(具体地说)上出现数字键盘,但在输入后隐藏每个字符。是否可能实现这样的功能?
<input type="tel|password">
对于iOS设备,您可以将输入类型设置为“password”,并仍然使用HTML5属性“pattern”触发数字键盘:
<input type="password" pattern="[0-9]*" ... />
从苹果文档中得知:
要显示数字键盘,请将pattern属性的值设置为 "[0-9]" 或 "\d"。
<input type="tel" name="password" id="password" value="" placeholder="Enter password"
onfocus="changeToPassword()">
Javascript:
// change the type of the input to password
function changeToPassword() {
setTimeout(function () {
document.getElementById("password").setAttribute("type", "password")
}, 500);
}
这个解决方案适用于iPhone。这是一种比较trick的方法。在接下来的500毫秒内,一旦你有了数字键盘,你就可以将属性更改为password,这样就能欺骗手机。
type="tel"
触发。我认为JS输入验证对此无济于事。 - Ilmari Karonen