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
HTML5 input number min max not working with required
提问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 HTML5
attributes like required
, pattern
, min
and max
? Seems like it is not working
我想强制用户输入他们的年龄。我还想确保他们只进入 18-99 之间。这是可能与HTML5
属性,如required
,pattern
,min
和max
?似乎它不起作用
<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
检查屏幕截图
回答by Praveen
回答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>