如何限制 HTML5“数字"中可能的输入?元素? [英] How can I limit possible inputs in a HTML5 "number" element?

查看:36
本文介绍了如何限制 HTML5“数字"中可能的输入?元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 元素,maxlength 不起作用.如何限制该数字元素的 maxlength?

For <input type="number"> element, maxlength is not working. How can I restrict the maxlength for that number element?

推荐答案

并且您可以添加一个 max 属性,该属性将指定您可以插入的最大可能数字

And you can add a max attribute that will specify the highest possible number that you may insert

<input type="number" max="999" />

如果同时添加 maxmin 值,则可以指定允许值的范围:

if you add both a max and a min value you can specify the range of allowed values:

<input type="number" min="1" max="999" />

以上内容仍不会阻止用户手动输入指定范围之外的值.相反,他将显示一个弹出窗口,告诉他在提交表单时输入此范围内的值,如下面的屏幕截图所示:

The above will still not stop a user from manually entering a value outside of the specified range. Instead he will be displayed a popup telling him to enter a value within this range upon submitting the form as shown in this screenshot:

这篇关于如何限制 HTML5“数字"中可能的输入?元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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