如何在 Datepicker 中禁用星期一?

How do I disable Mondays in Datepicker?


有人能帮我解决如何禁用星期一吗?
额外:如何防止某人手动输入他们自己的交货日期(即如果交货日历没有立即弹出)?

非常感谢您!

请在下面找到我当前的代码:-

if (window.jQuery) {
  let $ = window.jQuery;

  $(function() {
    // Dates to exclude
    var excludeDays = ['2021-09-04', '2021-09-12'];

    function disableSpecificDate(date) {
      // To disable specific day
      var dateArr = [String(date.getFullYear()), String(date.getMonth() + 1), String(date.getDate())];
      if (dateArr[1].length == 1) dateArr[1] = "0" + dateArr[1];
      if (dateArr[2].length == 1) dateArr[2] = "0" + dateArr[2];
      return excludeDays.indexOf(dateArr.join("-")) == -1;
    }
    $("#date").datepicker({
      dateFormat: 'dd/mm/yy',
      minDate: +1,
      maxDate: '+1M',
      beforeShow: function() {
        // To exclude next business day after 12 PM
        if (new Date().getHours() >= 12) {
          $(this).datepicker("option", "minDate", +2);
        }
      },
      beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day == 0 ? false : disableSpecificDate(date)), ''];
      }
    });
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

<div style="width:300px; clear:both;">
  <p>
    <input id="date" type="text" name="attributes[DELIVERY DATE]" value="" />
    <span style="display:block" class="instructions"></span>
  </p>
</div>

beforeShowDay 函数中使用 day == 1。我在这里禁用了星期日和星期一。

if (window.jQuery) {
  let $ = window.jQuery;

  $(function() {
    // Dates to exclude
    var excludeDays = ['2021-09-04', '2021-09-12'];

    function disableSpecificDate(date) {
      // To disable specific day
      var dateArr = [String(date.getFullYear()), String(date.getMonth() + 1), String(date.getDate())];
      if (dateArr[1].length == 1) dateArr[1] = "0" + dateArr[1];
      if (dateArr[2].length == 1) dateArr[2] = "0" + dateArr[2];
      return excludeDays.indexOf(dateArr.join("-")) == -1;
    }
    $("#date").datepicker({
      dateFormat: 'dd/mm/yy',
      minDate: +1,
      maxDate: '+1M',
      beforeShow: function() {
        // To exclude next business day after 12 PM
        if (new Date().getHours() >= 12) {
          $(this).datepicker("option", "minDate", +2);
        }
      },
      beforeShowDay: function(date) {
        var day = date.getDay();
        return [((day == 0 || day == 1) ? false : disableSpecificDate(date)), ''];
      }
    });
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" defer="defer"></script>

<div style="width:300px; clear:both;">
  <p>
    <input id="date" type="text" name="attributes[DELIVERY DATE]" value="" />
    <span style="display:block" class="instructions"></span>
  </p>
</div>