簡體   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"/>

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM