如何避免输入类型编号中的十进制值 [英] How to avoid Decimal values in input type number
本文介绍了如何避免输入类型编号中的十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何避免HTML5中Number输入中的小数.目前,它允许用户键入十进制值.
How to avoid Decimal values from input of Number in HTML5. Currently it allows user to type decimal value.
推荐答案
提供的答案的另一种方法是在输入时监视按键.我个人喜欢将type="number"
保留为属性.这是 JSFiddle
An alternative to the supplied answers is to monitor the keypress while in the input. I personally like leaving the type="number"
as an attribute. Here's a JSFiddle
<form action="#" method="post">
Numbers: <input name="num"
type="number"
min="1"
step="1"
onkeypress="return event.charCode >= 48 && event.charCode <= 57"
title="Numbers only">
<input type="submit">
</form>
这篇关于如何避免输入类型编号中的十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文