如何从jquery日期选择器禁用周末和特定时间后的前几天的假期

How to disable holidays with weekends and previous days after a certain time from jquery datepicker?

本文关键字:定时间 前几天 周末 假期 jquery 日期 选择器      更新时间:2023-09-26

我想创建一个jQuery日期选择器,其中周日将被禁用,前几天将被禁用(包括下午3点30分之后的今天),节假日也将被禁用。以下是我迄今为止所做的工作。有人能帮我怎么增加假期吗?

<!DOCTYPE html>
<html>
    <head>
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
        <script>
        var currentTime = new Date();
        if (currentTime.getHours() >=15 && currentTime.getMinutes() >=30) {
            $(document).ready(function() {
                $('#datepicker').datepicker({
                        minDate: 1,						
                    beforeShowDay: noSunday
                  });
                  function noSunday(date){
                      var day = date.getDay();
                                  return [(day > 0), ''];
                  }; 
            });
        } else {
            $(document).ready(function() {
                $('#datepicker').datepicker({
                        minDate: 0,						
                    beforeShowDay: noSunday
                  });
                  function noSunday(date){
                      var day = date.getDay();
                                  return [(day > 0), ''];
                  }; 
            });
        }
        </script>
    </head>
    <body>
        <form>
            <input id="datepicker" />
        </form>
    </body>
</html>

周日禁用和前几天禁用我只需要帮助禁用假日

var currentTime = new Date();
var timeCond = currentTime.getHours() >=15 && currentTime.getMinutes() >=30;
var holidays = ["1/12/2016"]; // add holidays
$(document).ready(function() {
    $('#datepicker').datepicker({
        minDate: timeCond?1:0,                      
        beforeShowDay: visibilityHandler
      });
      function visibilityHandler(date){
          if(holidays.indexOf(date.toLocaleDateString()) != -1)
             return [false,'']
          return noSunday(date);
      }
      function noSunday(date){
          var day = date.getDay();
                      return [(day > 0), ''];
      }; 
  });