gpt4 book ai didi

javascript - jQuery UI 日期选择器 - 禁用公共(public)假期、周末、上午 10 点后的第二天,仅允许星期二、星期三和星期四作为可选日期

转载 作者:行者123 更新时间:2023-11-28 07:40:28 27 4
gpt4 key购买 nike

我正在使用 JQuery UI Datepicker Disbale Next Day After 12pm 中的代码禁用周末、公共(public)假期和第二天(如果在上午 10 点之后选择),但我不知道如何只允许选择星期二、星期三和星期四。

// dates
var dateMin = new Date();
var weekDays = AddWeekDays(1);
dateMin.setDate(dateMin.getDate() + weekDays);
var natDays = [
[1, 1, 'uk'],
[12, 25, 'uk'],
[12, 26, 'uk']
];
function noWeekendsOrHolidays(date) {
var noWeekend = $j.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return noWeekend;
}
}
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}
function AddWeekDays(weekDaysToAdd) {
var mydate = new Date();
if (mydate.getHours()>=10)
var daysToAdd = 1;
else var daysToAdd = 0;
var day = mydate.getDay()
weekDaysToAdd = weekDaysToAdd - (5 - day)
if ((5 - day) < weekDaysToAdd || weekDaysToAdd == 1) {
daysToAdd = (5 - day) + 2 + daysToAdd
} else { // (5-day) >= weekDaysToAdd
daysToAdd = (5 - day) + daysToAdd
}
while (weekDaysToAdd != 0) {
var week = weekDaysToAdd - 5
if (week > 0) {
daysToAdd = 7 + daysToAdd
weekDaysToAdd = weekDaysToAdd - 5
} else { // week < 0
daysToAdd = (5 + week) + daysToAdd
weekDaysToAdd = weekDaysToAdd - (5 + week)
}
}

return daysToAdd;
}

$j('.input-text.addon.addon-custom').datepicker({
beforeShowDay: noWeekendsOrHolidays,
minDate : dateMin,
defaultDate: +1,
firstDay: 1,
changeFirstDay: true,
dateFormat: "DD, dd MM yy"
});

任何帮助将不胜感激。

在这里摆弄:http://jsfiddle.net/prydonian/4k4gga6j/

最佳答案

在您的日期选择器函数中,添加“beforeShowDay ”选项,如下所示。

jQuery('#datepicker').datepicker({
minDate: dateMin,
defaultDate: +1,
firstDay: 1,
changeFirstDay: true,
dateFormat: "DD, dd MM yy",
beforeShowDay: function(day){
if (day.getDay()<2 || day.getDay()>4){
return [false, ""];
}
return noWeekendsOrHolidays(day);
}
});

这是更新的 fiddle :http://jsfiddle.net/4k4gga6j/3/

关于javascript - jQuery UI 日期选择器 - 禁用公共(public)假期、周末、上午 10 点后的第二天,仅允许星期二、星期三和星期四作为可选日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28088439/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com