![](/img/trans.png)
[英]How to use an input type=text field to accept only digits, minus sign and decimals and nothing more with Angular
[英]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"/>
從
<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' >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.