admin管理员组

文章数量:1315353

I am using Chrome (Version 31.0.1650.63 m), and when I set a min date on a input type date via javascript, the min attribute is changed in the HTML but the datepicker doesn't use it.

What am I missing?

<input type="date" id="input" />
//...
document.getElementById('input').setAttribute("min", '2013-12-9');

Fiddle

I am using Chrome (Version 31.0.1650.63 m), and when I set a min date on a input type date via javascript, the min attribute is changed in the HTML but the datepicker doesn't use it.

What am I missing?

<input type="date" id="input" />
//...
document.getElementById('input').setAttribute("min", '2013-12-9');

Fiddle

Share Improve this question edited Jan 9, 2014 at 17:45 Rikard asked Jan 9, 2014 at 17:37 RikardRikard 7,80513 gold badges60 silver badges99 bronze badges 7
  • Change the option in the fiddle on the left from "onload", to "no-wrap in body", and it adds the attribute. – adeneo Commented Jan 9, 2014 at 17:40
  • @adeneo, no difference: jsfiddle/5UbPs/2 - and as I said, I see the min="2013-12-9"in the HTML, it just doesn't work... – Rikard Commented Jan 9, 2014 at 17:43
  • This works for me on Chrome Version 32.0.1700.72 m – stackErr Commented Jan 9, 2014 at 17:44
  • @stackErr, I'm using Version 31.0.1650.63 m. Do you get it to work out of the box with my fiddle? – Rikard Commented Jan 9, 2014 at 17:45
  • @Rikard yeah in your fiddle...from the datepicker, everything before 2013-12-09 is grayed out. Though I can manually input any date I want – stackErr Commented Jan 9, 2014 at 17:47
 |  Show 2 more ments

1 Answer 1

Reset to default 6

According to w3c (http://dev.w3/html5/markup/input.date.html) you just need leading zero in the day:

Instead of 2013-12-9

must be 2013-12-09

http://jsfiddle/edgarinvillegas/5UbPs/9/

It works :)

Cheers, from La Paz, Bolivia

本文标签: htmlinput type date and min value set by javascriptStack Overflow