我想使用日期选择器作为“历史上的这一天”项目的一部分。
这个想法是,用户选择一天,比如“11 月 20 日”,该项目就会向他展示不同年份这一天发生的历史事件。
鉴于他们选择的是通用日期,而不是特定日期(例如“2013 年 11 月 20 日”),我希望日期选择器与年份无关。
Several people have asked类似的东西,但他们寻求隐藏年份的方法。
我不想隐藏年份。我希望选择器忽略年份。
第一周开始时不应有日期标签(“星期一”、“星期二”等),也不应有空白日期。以 2 月为例,它将列出 29 天。
所以,不要像这样......
NOVEMBER
Mo Tu We Th Fr Sa Su
-- -- -- 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
...应该是这样的
NOVEMBER
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
有没有办法修改 jQuery UI 的日期选择器以使其像这样工作?或者是另一个为其日期选择器提供无年份选项的库?
最佳答案
您可以通过重写 Date.prototype.getDay() 方法来做到这一点:
JS:
$(function() {
//override getDay()
Date.prototype.getDay = function() {
//change getDay() so that the first day of the month is always at
// the beginning of the week
return ((this.getDate()-1) % 7);
}
//create the datepicker that does not display year
$( "#datepicker" ).datepicker({dateFormat: "d MM"});
});
CSS(隐藏日期选择器中的年份和日期):
.ui-datepicker-year, .ui-datepicker-calendar thead {
display: none;
}
关于javascript - 有没有办法让 jQuery datepicker 无需几年就能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20129174/