如何在jQuery UI日期选择器中禁用公共假期?

问题描述:

我正在申请假期预订,显然您不需要预订已经给您的假期,因此我需要知道如何禁用圣诞节,例如每年从日期选择器中禁用我每年都必须更改代码.

I'm making a holiday booking application and obviously you don't need to book off holidays that are already given to you, so I need to know how I can disable, Christmas, for example from the date picker every year without me having to change the code every year.

这是到目前为止我的jQuery UI日期选择器代码:

This is my jQuery UI date picker code so far:

<script>
$(function() {
  $("#from").datepicker({
      beforeShowDay: $.datepicker.noWeekends,
      defaultDate: "today",
      changeMonth: true,
      numberOfMonths: 1,
      minDate: "today",
      dateFormat: "dd/mm/yy",
      onClose: function(selectedDate) {
        $( "#to" ).datepicker("option", "minDate", selectedDate);
      }
  });
  $("#to").datepicker({
    beforeShowDay: $.datepicker.noWeekends,
    defaultDate: "today",
    changeMonth: true,
    numberOfMonths: 1,
    minDate: "today",
    dateFormat: "dd/mm/yy",
    onClose: function(selectedDate) {
      $("#from").datepicker("option", "maxDate", selectedDate);
    }
  });
});
</script>

您可以排除日期,例如

var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
    var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
    return [ holidays.indexOf(datestring) == -1 ]
}
});

您可以为假期数组提供更多日期

you can provide more dates to the holidays array