0

I have a five-month Datepicker inline calendar. startDate is a variable I wrote which is set by a user click event. I am adjusting the minDate and maxDate options after init by doing this:

$('#datepicker').datepicker("option",{"minDate":startDate,"maxDate":endDate}).datepicker("refresh");

However, when the calendar is refreshed, it displays the first month according to the startDate variable, which is disorienting. For example, I have the calendar init in January and it shows through May. When startDate happens to be in a later month, say February, then when I refresh the calendar, it displays starting from that month (February) and disables all dates up to the one selected. I'd like to freeze the calendar so that it always shows January through May, yet blacks out all the dates up to minDate.

Is there an easy way to freeze the calendar so that it displays a specific 5-month range regardless of the minDate and maxDate settings?

Thanks in advance.

4

4 回答 4

2

我试图破解 minDate 和 maxDate 功能,以便在所选日期之前涂黑日期。我没有这样做,而是构建了一个日期对象数组,我将其提供给 beforeShowDay,如下所示:

   $('#datepicker').datepicker({
            ...
            beforeShowDay: setRestrictedDates,
            ...
   })
 function setRestrictedDates(date) {
  var arrLen = jsForbiddenDatesArray.length;
  for (var x=0; x<arrLen; x++) {
   var arraydate = jsForbiddenDatesArray[x];
   var arraytime = Math.round( new Date(arraydate).getTime() / 86400000 );
   var dtime = Math.round( date.getTime() / 86400000 );
   if ( dtime == arraytime || date.getDay() == 5) {
    return [false, ''];
    break;
   }
  }
  return $.datepicker.noWeekends(date);
 }

请注意,通过除以 86400000 设置 dtime 只会将日期转换为天数,以便我可以比较以确保两天相同(dtime == arraytime)。此外,OR 语句“date.getDay() == 5”选择所有星期五。这与 datepicker.noWeekends(date) 相结合,意味着我有周末和周五,以及我的禁止日期数组中的任何日期。

我希望这可以帮助别人。为 datepicker 设置中断日期非常方便,但我发现这样做的文档晦涩难懂,甚至不存在。

感谢这里和 jQuery 论坛中帮助我解决这个问题的每个人。

于 2010-06-24T11:53:22.240 回答
1

约翰 -

我遇到了同样的问题,并在网上找到了一个非常酷的解决方案。它使日期范围的可视化变得非常容易,对于我的应用程序来说,预设的日期范围选择非常酷。

http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/

“范围”功能在底部附近进行了详细说明。如果您对此进行测试,请确保不要忘记链接相关的 CSS 文件,因为它会创建或破坏脚本。

祝你好运。

于 2010-06-24T15:19:59.247 回答
1
$("#datepicker").datepicker({ showCurrentAtPos: new Date().getMonth(), numberOfMonths: 12, minDate: startDate, maxDate: endDate});
于 2010-06-22T20:55:42.217 回答
1

您可以尝试将刷新放在选项之前吗?

于 2010-06-22T19:51:29.733 回答