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

浙公网安备 33010602011771号