input输入框进行限制

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

posted @ 2021-01-03 15:46  火烧云Z  阅读(202)  评论(0)    收藏  举报