Home > Web Front-end > JS Tutorial > How Can I Exclude Weekends and Holidays from jQuery UI Datepicker?

How Can I Exclude Weekends and Holidays from jQuery UI Datepicker?

DDD
Release: 2024-11-19 04:25:02
Original
720 people have browsed it

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
});
Copy after login

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;
  }
}
Copy after login

Then use it in the beforeShowDay option:

$(".selector").datepicker({
  beforeShowDay: noWeekendsOrHolidays
});
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template