jQuery UI 日期选择器 - 禁用节假日和星期六 - 添加星期五
jQuery UI Datepicker - Disable Holidays and Saturdays - Add Friday
我的日期选择器当前禁用假期和周末。我正在尝试将星期五添加到脚本中
var holidays = <?php echo $holidays; ?>;
// var holidays =[ [2020,01,01,'New Years Day'],[2020,04,21,'My Birthday'],[2020,12,25,'Christmas Day'] ];
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}
$( ".add_delivery_date").datepicker( {
firstDay: 0,
beforeShowDay: setHolidays
});
您可以在 setHolidays
函数中添加另一个检查以检查星期五的日期。
我在假期数组的循环之后添加了检查:
//var holidays = <?php echo $holidays; ?>;
var holidays =[ [2020,01,01,'New Years Day'],[2020,04,21,'My Birthday'],[2020,12,25,'Christmas Day'] ];
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
if (date.getDay() === 5) { // No Friday's
return [false, '', ''];
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}
$(document).ready(function () {
$( ".add_delivery_date").datepicker( {
firstDay: 0,
beforeShowDay: setHolidays
});
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
Date: <input type="text" class="add_delivery_date"> <br />
我的日期选择器当前禁用假期和周末。我正在尝试将星期五添加到脚本中
var holidays = <?php echo $holidays; ?>;
// var holidays =[ [2020,01,01,'New Years Day'],[2020,04,21,'My Birthday'],[2020,12,25,'Christmas Day'] ];
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}
$( ".add_delivery_date").datepicker( {
firstDay: 0,
beforeShowDay: setHolidays
});
您可以在 setHolidays
函数中添加另一个检查以检查星期五的日期。
我在假期数组的循环之后添加了检查:
//var holidays = <?php echo $holidays; ?>;
var holidays =[ [2020,01,01,'New Years Day'],[2020,04,21,'My Birthday'],[2020,12,25,'Christmas Day'] ];
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
if (date.getDay() === 5) { // No Friday's
return [false, '', ''];
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}
$(document).ready(function () {
$( ".add_delivery_date").datepicker( {
firstDay: 0,
beforeShowDay: setHolidays
});
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
Date: <input type="text" class="add_delivery_date"> <br />