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

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

问题描述

对于< input type =number> 元素, maxlength 不起作用。如何限制该数字元素的 maxlength

解决方案

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

 < input type =numbermax =999/> 

如果您同时添加 max 和a min 值,您可以指定允许值的范围:

 < input type =numbermin =1max =999/> 

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


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

解决方案

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

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

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天全站免登陆