Jquery 新 Chrome 浏览器上的日期时间选择器问题
Jquery datetimepicker issue on new Chrome browser
我根据当前时间禁用了日期时间选择器的时间。
此功能适用于 Windows 10 + Chrome 所有版本,但不适用于 Mac OS + chrome 76,78,79.
$(function() {
/* $('#datetimepicker').datetimepicker({ maxDate: new Date() ,*/
var fivedays;
fivedays = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 32);
//fivedays = new Date(new Date().getFullYear(), new Date().getMonth()+1);
var dt = $('#datetimepicker');
dt.datetimepicker({
minDate: new Date(),
maxDate: fivedays,
beforeShowDay: function(date) {
if (date.getDay() > 0 && date.getDay() < 6) {
return [true, ''];
} else {
return [true, ''];
}
},
monthStart: new Date().getMonth(),
monthEnd: new Date().getMonth(),
yearStart: new Date().getFullYear(),
yearEnd: new Date().getFullYear(),
prevButton: true,
nextButton: true,
timepicker: false,
format: 'Y/m/d',
scrollMonth: false,
scrollInput: false
});
dt.on('change', function() {
var selectedDate = $(this).val();
var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
var min = (new Date().getMinutes());
var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);
if (new Date(selectedDate) > new Date()) {
$('#datetimepicker3').find('option[disabled]').removeAttr('disabled');
} else {
$.each($('#datetimepicker3').children("option").not(':first'), function() {
if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
$(this).prop("disabled", true);
} else {
$(this).removeAttr("disabled");
}
});
}
});
var dt2 = $('#datetimepicker2');
//var dtset2 = new Date(new Date(dt).getFullYear(), new Date(dt).getMonth(), new Date(dt).getDate());
dt2.datetimepicker({
minDate: new Date(),
maxDate: fivedays
//dt2.datetimepicker({ minDate: dt, maxDate: dt
,
beforeShowDay: function(date) {
if (date.getDay() > 0 && date.getDay() < 6) {
return [true, ''];
} else {
return [false, ''];
}
},
monthStart: new Date().getMonth(),
monthEnd: new Date().getMonth(),
yearStart: new Date().getFullYear(),
yearEnd: new Date().getFullYear(),
prevButton: true,
nextButton: true,
timepicker: false,
format: 'Y/m/d',
scrollMonth: false,
scrollInput: false
});
dt2.on('change', function() {
var selectedDate = $(this).val();
var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
var min = (new Date().getMinutes());
var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);
if (new Date(selectedDate) > new Date()) {
$('#datetimepicker4').find('option[disabled]').removeAttr('disabled');
} else {
$.each($('#datetimepicker4').children("option").not(':first'), function() {
if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
$(this).prop("disabled", true);
} else {
$(this).removeAttr("disabled");
}
});
}
});
// $('#datetimepicker3').datetimepicker({ showClear: true, format: "H:i", timerangepicker:true, datepicker:false, step: 30, minTime: "7.00", maxTime: "19.00"});
// $('#datetimepicker4').datetimepicker({ format: 'H:i', datepicker:false, step: 30,minTime: "7.00", maxTime: "19.00"});
});
我发现没有问题,但跨浏览器平台上的日期设置为不同的时区,因此我没有禁用时间。
我根据当前时间禁用了日期时间选择器的时间。 此功能适用于 Windows 10 + Chrome 所有版本,但不适用于 Mac OS + chrome 76,78,79.
$(function() {
/* $('#datetimepicker').datetimepicker({ maxDate: new Date() ,*/
var fivedays;
fivedays = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 32);
//fivedays = new Date(new Date().getFullYear(), new Date().getMonth()+1);
var dt = $('#datetimepicker');
dt.datetimepicker({
minDate: new Date(),
maxDate: fivedays,
beforeShowDay: function(date) {
if (date.getDay() > 0 && date.getDay() < 6) {
return [true, ''];
} else {
return [true, ''];
}
},
monthStart: new Date().getMonth(),
monthEnd: new Date().getMonth(),
yearStart: new Date().getFullYear(),
yearEnd: new Date().getFullYear(),
prevButton: true,
nextButton: true,
timepicker: false,
format: 'Y/m/d',
scrollMonth: false,
scrollInput: false
});
dt.on('change', function() {
var selectedDate = $(this).val();
var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
var min = (new Date().getMinutes());
var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);
if (new Date(selectedDate) > new Date()) {
$('#datetimepicker3').find('option[disabled]').removeAttr('disabled');
} else {
$.each($('#datetimepicker3').children("option").not(':first'), function() {
if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
$(this).prop("disabled", true);
} else {
$(this).removeAttr("disabled");
}
});
}
});
var dt2 = $('#datetimepicker2');
//var dtset2 = new Date(new Date(dt).getFullYear(), new Date(dt).getMonth(), new Date(dt).getDate());
dt2.datetimepicker({
minDate: new Date(),
maxDate: fivedays
//dt2.datetimepicker({ minDate: dt, maxDate: dt
,
beforeShowDay: function(date) {
if (date.getDay() > 0 && date.getDay() < 6) {
return [true, ''];
} else {
return [false, ''];
}
},
monthStart: new Date().getMonth(),
monthEnd: new Date().getMonth(),
yearStart: new Date().getFullYear(),
yearEnd: new Date().getFullYear(),
prevButton: true,
nextButton: true,
timepicker: false,
format: 'Y/m/d',
scrollMonth: false,
scrollInput: false
});
dt2.on('change', function() {
var selectedDate = $(this).val();
var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
var min = (new Date().getMinutes());
var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);
if (new Date(selectedDate) > new Date()) {
$('#datetimepicker4').find('option[disabled]').removeAttr('disabled');
} else {
$.each($('#datetimepicker4').children("option").not(':first'), function() {
if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
$(this).prop("disabled", true);
} else {
$(this).removeAttr("disabled");
}
});
}
});
// $('#datetimepicker3').datetimepicker({ showClear: true, format: "H:i", timerangepicker:true, datepicker:false, step: 30, minTime: "7.00", maxTime: "19.00"});
// $('#datetimepicker4').datetimepicker({ format: 'H:i', datepicker:false, step: 30,minTime: "7.00", maxTime: "19.00"});
});
我发现没有问题,但跨浏览器平台上的日期设置为不同的时区,因此我没有禁用时间。