Html HTML5 输入数字最小值最大值不适用于必需的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17872928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:31:56  来源:igfitidea点击:

HTML5 input number min max not working with required

csshtml

提问by user1330974

I would like to force the user to type their age. I also would like to make sure they only enter between 18-99. Is that possible with HTML5attributes like required, pattern, minand max? Seems like it is not working

我想强制用户输入他们的年龄。我还想确保他们只进入 18-99 之间。这是可能与HTML5属性,如requiredpatternminmax?似乎它不起作用

<form>
    <input type="number" name="Q2age" id="Q2age" size="10" min="18" max="99" pattern="[1-8][0-9]" required>
    <button type="submit" class="button" id="test">Submit</button>
</form>

Am I doing something wrong here? I use Firefox 22.0 on Ubuntu 12.0.4LTS (tested on Chrome as well, but doesn't work.) Thank you for your help.

我在这里做错了吗?我在 Ubuntu 12.0.4LTS 上使用 Firefox 22.0(也在 Chrome 上测试过,但不起作用。)谢谢你的帮助。

采纳答案by Arun Bertil

This is the expected behaviour because FF21 doesnt supports min,max attribute...

这是预期的行为,因为 FF21 不支持 min,max 属性...

you can check it in http://html5test.com/

您可以在http://html5test.com/ 中查看

Check the screenshot enter image description here

检查屏幕截图 在此处输入图片说明

回答by Praveen

Your code works fine. Check this fiddle(I'm using latest chrome)

你的代码工作正常。检查这个小提琴(我使用的是最新的 chrome)

My only concern you is your pattern="[1-8][0-9]"can simple use this

我唯一关心的是你pattern="[1-8][0-9]"可以简单地使用这个

pattern="[0-9]{2}"

回答by web2008

It doesn't work in Firefox but it works in Chrome, Internet Explorer, Safari and Opera.

它不适用于 Firefox,但适用于 Chrome、Internet Explorer、Safari 和 Opera。

Please find the working demo here: Demo

请在此处找到工作演示:演示

<form action="">

<input type="number" name="points" min="1" max="10" name="Q2age" id="Q2age" required>

 <input type="submit" value="submit" />
</form>