如何在 jQuery UI 日期选择器中禁用公共假期? [英] How do i disable public holidays in a jQuery UI date picker?

查看:31
本文介绍了如何在 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

这篇关于如何在 jQuery UI 日期选择器中禁用公共假期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆