今天接到老板的需求,登录密码的时候需要弹出手机键盘。
原代码为:<input type="password">
#解决方案一:
<input type="tel" class="password" maxlength="6" pattern="[0-9]*" />
你以为解决了?没有这里虽然会弹出数字键盘 但是输入是明文的。所以我们需要继续优化一下
<style>
input[type="tel" i].password {
-webkit-text-security: disc;
}
</style>
事情完美解决了.
苹果和安卓都测试通过了。
另外还有一种方法
<input type="password" pattern="[0-9]*" onkeyup="this.value=this.value.replace(/\D/g,'');" onafterpaste="this.value=this.value.replace(/\D/g,'');">