1

I'm using jQuery's date-picker and specifying a minimum date of today and maximum date of Jan 31st. When the calendar shows up, however, the 31st cannot be selected, despite the code looking correct.

Here's the code:

function initializePickers() {
  jQuery('.date-start').each(function() {
      startEndPickers(this);
  });
  jQuery('.date-end').each(function() {
      startEndPickers(this);
  });
}

function startEndPickers(input) {
  jQuery(input).datepicker({
      dateFormat: "M dd, yy",
      minDate: new Date(),
      maxDate: new Date('2014-01-31')
  });
}

And here is a jsFiddle which demonstrates the inability to pick January 31st: http://jsfiddle.net/Hec5m/

Anyone know what's causing this? The maxDate is clearly specified as the 31st, not the 30th.

4

1 回答 1

2

new Date('2014-01-31')选择 1 月 31 日午夜,这意味着一天中的任何时间都无法选择,这就是它被排除在外的原因。

您可以通过使用2014-02-01最大日期 ( jsFiddle ) 或指定时间以及结束日期23:59:59( jsFiddle ) 来解决此问题。

jQuery UI 还允许您将字符串作为参数放入(与您的日期格式相同的方式 -"Jan 31, 2014"在您的情况下),而不是传入一个Date对象,该对象的行为与您预期的一样。( jsFiddle )

于 2013-12-21T23:59:31.373 回答