我想使用input type = text,但只使用keyin编号,如何不允许用户keyin减号( - )?
<input required type="text" pattern="[0-9]*" name="discount" placeholder='not allow negative' >
答案 0 :(得分:3)
只需输入类型编号并添加min属性,因此您的代码必须像这样
<input type="number" min="0"/>
答案 1 :(得分:1)
从
改变<input required type="text" pattern="[0-9]*" name="discount" placeholder='not allow negative' >
到
<input required type="text" onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57" name="discount" placeholder='not allow negative' >