我使用jQuery datepicker来展示用户可用日期,并希望禁用并标记为红色的忙碌日期。我使用了datepicker选项中的beforeShowDay:
beforeShowDay: function(date) {
var cssClass = '';
for (var i=0; i < busyStarts.length; i++) {
var busyStart = new Date(busyStarts[i]);
var busyEnd = new Date(busyEnds[i]);
if (date >= busyStart && date <= busyEnd) {
cssClass = 'ui-state-disabled busy_date';
}
}
return [true, cssClass];
}
busyStarts 和 busyEnds 变量是:
但是我看到的结果是:
为什么时间间隔的前几天没有被选中?因为我有条件date >= busyStart
当我查看调试器时:
这就是为什么等于 (=) 条件无法工作。开始和结束日期带有时间 03:00:00,但日期带有 00:00:00,在相同的日期下, 因为 00:00:00 < 03:00:00,所以date <=。
现在我问,为什么?如何正确解决这个问题?