6ovo6

属性maxLength,只能同 text和 password 类型一同使用

<input type="text" maxlength="8"/>

限制input输入框为纯数字,onkeyup

<input type="text" onkeyup="value=value.replace(/[^\d]/g,\'\')"  maxlength="8"/>

oninput,本人测试输入非数字时,虽然起到了输入不进去,但是数字会跟着减少

<input type="text" oninput="value=value.replace(/[^\d]/g,\'\')" maxlength="8"/>

也可以使用js,但是js有一个渲染时间,没有maxlength的效果好

分类:

技术点:

相关文章:

  • 2021-08-01
  • 2021-10-19
  • 2021-12-08
  • 2021-11-28
  • 2021-12-08
  • 2021-08-01
  • 2021-10-12
猜你喜欢
  • 2021-11-13
  • 2021-12-28
  • 2021-12-09
  • 2021-12-08
  • 2021-12-09
  • 2021-11-18
相关资源
相似解决方案