How to make type=“number” to positive numbers only

后端 未结 17 2410
既然无缘
既然无缘 2020-11-30 17:12

currently I have the following code


it comes out to something like this

17条回答
  •  旧巷少年郎
    2020-11-30 17:54

    You can force the input to contain only positive integer by adding onkeypress within the input tag.

    Here, event.charCode >= 48 ensures that only numbers greater than or equal to 0 are returned, while the min tag ensures that you can come to a minimum of 1 by scrolling within the input bar.

提交回复
热议问题