如何限制html输入框,使其仅接受数字输入? [英] How can I limit a html input box so that it only accepts numeric input?

查看:122
本文介绍了如何限制html输入框,使其仅接受数字输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html输入框,但是只有数字数据才是数据.我该如何执行呢?

I have an html input box, but only numeric data is data. How can I enforce that?

推荐答案

您可以使用HTML5来验证输入的类型,而无需使用JavaScript.但是,并非所有浏览器都支持此方法.

You can use HTML5 to validate the type of your input without using JavaScript. However, this method is not (yet) supported by all browsers.

<input type="number" name="quantity" min="1" max="5">

使用以下属性指定限制(如此处所述):

Use the following attributes to specify restrictions (as described here):

  • 最大值-指定允许的最大值
  • 分钟-指定允许的最小值
  • 步骤-指定合法编号间隔
  • -指定默认值
  • max - specifies the maximum value allowed
  • min - specifies the minimum value allowed
  • step - specifies the legal number intervals
  • value - Specifies the default value

这篇关于如何限制html输入框,使其仅接受数字输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆