如何在输入数字时在输入类型数字中显示屏蔽字符(如星号"*")



我正在使用html input type ='number'字段设置pin no(不允许字符),但我希望字符在我输入时掩盖。

我是Web开发的新手。请帮助我。

您可以这样使用 -

<input type="password" pattern="[0-9]*" inputmode="numeric">

请参阅此处的详细信息

https://developer.mozilla.org/en-us/docs/web/html/element/input/input/input/passwordwordwordwordwordwordting_length_requirements

我认为,如果您想制作输入类型='密码'仅接受数字

,这会有所帮助

用jquery

解决方案

$(function () {
  $('#pincode').bind('keyup paste', function () {
    this.value = this.value.replace(/[^0-9]/g, '');
  });
  $('#pincode').keyup(function () {
    var text = $(this).val().trim();
    $('#errorname').text(text);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="" method="post" id="sign_in_form">
  <div class="form-group">
    <label for="email" style="font-weight: bold; cursor: text;"><span style="color:red;">* </span>Enter PIN</label>
    <input type="password" name="pincode" id="pincode" maxlength="6" inputmode="numeric">
  </div>
  <div id="errorname"></div>
</form>

最新更新