html5 输入密码时怎么改键盘样式为数字键盘

html5在移动端输入密码时怎么改键盘样式为数字键盘?
当 <input type="number">时,弹出来的是数字键盘。
怎么样使 <input type="password">时更改键盘也为数字键盘?

阅读 12k
4 个回答

可以设置两个input框,把input设置为绝对定位,上层

<input type='number' val='' style='z-index=10' />

设置透明度为0,下层

<input type='password' val='' style = 'z-index=1' />

这样,当你点击input框的时候触发上层input框,即可弹出数字框,然后把数字框value通过js传给下层的input,即为密码,这样模拟实现你说的效果

添加类名和CSS,修改type="tel",在手机上看会弹出数字键盘。

<!--CSS-->
<style>
input[type="tel" i].password {
    -webkit-text-security: disc;
}
</style>

<!--html-->
<input type="tel" class="password" maxlength="6" pattern="[0-9]*" />

clipboard.png
给你的input给个onkeyup="NumberCheck(this)

<input type="password" pattern="[0-9]*" onkeyup="this.value=this.value.replace(/\D/g,'');" onafterpaste="this.value=this.value.replace(/\D/g,'');">
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题