jQuery UI Datepicker:在< select>中显示所有12个月本年度?
我在以下选项中使用 jQuery UI Datepicker :
$('#birth_date').datepicker({
changeMonth: true,
changeYear: true,
minDate: new Date(-2206281600*1000),
maxDate: new Date(1298653687*1000),
yearRange: '1900:2011'
});
效果很好.月份和年份显示为2个并排的<select>
框.问题是,我们只是在2011年2月.因此,当用户输入出生日期(例如12月)时,该月份尚不可用.他们必须先选择年份,然后才能选择月份.
Works pretty well. The month and year are displayed as 2 side-by-side <select>
boxes. The problem is, we're only in Feb of 2011. So when the user goes to enter their birth date, to say, Dec, that month isn't available yet. They have to choose their year first before the month becomes selectable.
即使那几个月不是当年的有效选项,我如何才能显示全部12个月?
How can I get into to display all 12 months, even if those months aren't valid options for the current year?
对于仍在寻找的任何人,我最终都使用defaultDate来解决此问题:
For anyone still looking, I ended up using defaultDate to fix this:
$( ".selector" ).datepicker({
changeMonth: true,
changeYear: true,
minDate: '-100Y', //100 Years Old
maxDate: '0' //Today
defaultDate: '-1Y', //Default to One Year Ago to show 12 months
yearRange: '-100:+0' //Show 100
});
它仍然限制了日期范围,因此将来没有人可以选择日期,并且不依赖用户按特定顺序输入.
It still limits the date range so no one can pick a date in the future, and doesn't rely on the user inputting in a particular order.