Home > Article > Web Front-end > How Can I Exclude Weekends and Holidays from jQuery UI Datepicker?
Excluding Saturdays, Sundays, and Holidays from jQuery UI Datepicker
You're using a jQuery UI datepicker to schedule appointments within the next month, but you want to exclude Saturdays and Sundays. The beforeShowDay option provides a customizable solution for this.
beforeShowDay Option
This option takes a callback function that returns an array containing two elements:
Example: Exclude Weekends
To exclude weekends using the built-in noWeekends function, simply add it to the beforeShowDay option:
$(".selector").datepicker({ beforeShowDay: $.datepicker.noWeekends });
Example: Combine with National Holidays
If you also want to exclude specific national holidays, you can define a custom callback function and combine it with noWeekends:
function noWeekendsOrHolidays(date) { var noWeekend = $.datepicker.noWeekends(date); if (noWeekend[0]) { return nationalDays(date); } else { return noWeekend; } }
Then use it in the beforeShowDay option:
$(".selector").datepicker({ beforeShowDay: noWeekendsOrHolidays });
Note: In jQuery UI 1.8.19 and later, the beforeShowDay option also allows an optional third parameter for a tooltip message on disabled dates.
The above is the detailed content of How Can I Exclude Weekends and Holidays from jQuery UI Datepicker?. For more information, please follow other related articles on the PHP Chinese website!