在Jquery UI日历中禁用了未来一周



我需要为jqueryUI日历禁用未来几周,我尝试了禁用未来日期的东西。但我想禁用未来的一周,它也禁用了第52周的其他日期。如果有人能在这方面帮助我,请帮忙。下面是我工作的链接。在这里你可以看到第52周的禁用日期。我想要整个星期的选择。

到目前为止,我已经完成了Fiddle Link。

<input type="text" class="form-control weekcal-x" name="start" id="start" custom="" />
$(".weekcal-x").datepicker({
  showWeek: true,
  firstDay: 1,
  maxDate: new Date,
  onSelect: function(dateText, inst) {
    $(this).val("Week " + $.datepicker.iso8601Week(new Date(dateText)) + ', ' + $.datepicker.formatDate("yy", new Date(dateText)));
  }
}).datepicker('widget').addClass('ui-weekpicker');
$('.ui-weekpicker').on('mousemove', 'tr', function() {
  $(this).find('td a').addClass('ui-state-hover');
});
$('.ui-weekpicker').on('mouseleave', 'tr', function() {
  $(this).find('td a').removeClass('ui-state-hover');
});

试试这个

maxDate: +7而不是maxDate: new Date

更新

获取本周的第一天和最后一天:

var currentDate = new Date; // get current date
var first = currentDate.getDate() - currentDate.getDay() + 1; // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6
var firstday = new Date(currentDate.setDate(first));
var lastday = new Date(currentDate.setDate(last));

现在您可以随心所欲地使用它们,如maxDate: lastday, minDate:firstday

最新更新