我无法理解如何设置 jquery Datepicker 的最小/最大日期。当我检查 docs ,我发现 dateformat
应该出现在 new Date(2009, 1 - 1, 26)
中。
1-1
是什么意思?当我检查w3c时js 日期格式学校,我找不到这个。
所以我尝试了
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yyyy-mm',
minDate: new Date(2001-01),
maxDate: '+15Y'
});
但这给我留下了完全随机的结果......它从 2006 年开始到 2026 年结束。
这是 fiddle http://jsfiddle.net/ANF2y/58/
最佳答案
在 JavaScript 中,月
的计算范围是 0 到 11。因此,在创建新日期时,请使用当前月份 - 1。
1 - 1
等于 0
。所以这是一个有效的月份(0 - 一月
)。
在您的情况下,设置minDate
如下。
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
minDate: new Date(2001, 0, 1),
maxDate: '+15Y',
dateFormat: 'yyyy-mm'
});
that is because the jquery date picker only shows 15 items at a time, there is no max date set so you can go as far in the future as you want. When it is set to 2001 you see 2006 in the dropdown as it is limited to 15 items. Select 2006 and then you'll see 2001 in the dropdown. Is your question can I show more items in the year dropdown list?
关于javascript - 设置 jquery Datepicker 的最小/最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39660124/