min/max attribute with type = date on HTML5

守給你的承諾、 提交于 2019-12-01 07:02:23

问题


I'm having some problems to set a minimum and a maximum YEAR with HTML5 date input.

Here is my code:

<input required="required"  min="1900-01-01" max="2099-09-13" type="date" class="form-control" id="inputDataNascimento">

It doesn't work at all.

Am I doing something wrong? Is this a bug?

Notes: I'm using Google Chrome and Twitter Bootstrap 3.


回答1:


Some browsers like Safari and Internet Explorer does not support this functionality, this may be your problem. Write validation via Javascript.

The list of browers that support this feature can be seen at:...

http://html5test.com/compare/browser/chrome-33/firefox-27/opera-19/safari-7.0/ie-11.html




回答2:


min and max attributes for date input type have very little browser support. You can use jQuery validation as a workaround.

<input id="dateInput" required="required"  min="1900-01-01" max="2099-09-13" type="date" class="form-control" id="inputDataNascimento">
<script>
    $("#dateInput").validate();
</script>


来源:https://stackoverflow.com/questions/22232638/min-max-attribute-with-type-date-on-html5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!