简体   繁体   English

如何使type =“ text”不键入减号(-)?

[英]How to make type=“text” not to key Minus sign (-)?

我想使用输入类型=文本,但只使用键入数字,如何不允许用户键入减号(-)?

<input required type="text" pattern="[0-9]*" name="discount" placeholder='not allow negative'  >

只需输入类型编号并添加min属性,因此您的代码必须像这样

<input type="number" min="0"/>

change from

<input required type="text" pattern="[0-9]*" name="discount" placeholder='not allow negative' >

to

<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' >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM