[英]jQuery datepicker start date interval not showing
I use jQuery datepicker for showing users available days and wants to disable and mark red busy days. 我使用jQuery datepicker显示用户可用的天数,并希望禁用并标记红色忙碌的日子。 I use for this beforeShowDay datepicker option:
我用这个beforeShowDay datepicker选项:
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 and busyEnds variables are: busyStarts和busyEnds变量是:
But I see this result: 但是我看到了这个结果:
the first days of intervals are not selected. 没有选择间隔的第一天。 Why?
为什么? I have condition date >= busyStart
我有条件日期> = busyStart
When I looked into debugger: 当我查看调试器时:
That's why equal (=) condition didn't work. 这就是为什么equ(=)条件不起作用的原因。 Start and End dates with time 03:00:00 but date with 00:00:00 and when dates the same date <= at the same day because 00:00:00 < 03:00:00.
开始和结束日期时间为03:00:00,但日期为00:00:00,当日期为同一天 <=同一天,因为00:00:00 <03:00:00。
Now I ask, WHY? 现在我问,为什么? And how to resolve this correct?
以及如何解决这个问题?
RESOLVED 解决
I have changed my code. 我改变了我的代码。 Added setHours(0, 0, 0, 0) to start and end dates initialization.
添加setHours(0,0,0,0)以开始和结束日期初始化。
beforeShowDay: function(date) {
var cssClass = '';
for (var i=0; i < busyStarts.length; i++) {
var busyStart = new Date(busyStarts[i]).setHours(0, 0, 0, 0);
var busyEnd = new Date(busyEnds[i]).setHours(0, 0, 0, 0);
if (date >= busyStart && date <= busyEnd) {
cssClass = 'ui-state-disabled busy_date';
}
}
return [true, cssClass];
}
Try this statement: 试试这句话:
beforeShowDay: function(date) {
var cssClass = '';
for (var i=0; i < busyStarts.length; i++) {
var date = new Date(date),
busyStart = new Date(busyStarts[i]),
busyEnd = new Date(busyEnds[i]);
if (date.getTime() >= busyStart.getTime() && date.getTime() <= busyEnd.getTime()) {
cssClass = 'ui-state-disabled busy_date';
}
}
return [true, cssClass];
}
getTime() converts your Date object to the time passed since January 1, 1970, 00:00:00 UTC in milisecond. getTime()将您的Date对象转换为自1970年1月1日00:00:00 UTC以毫秒为单位传递的时间。 This gives you an integer that you can easily compare.
这为您提供了一个可以轻松比较的整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.