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的效果好

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-07-24
  • 2021-11-18
相关资源
相似解决方案