【问题标题】:Disable dates further than 2 days from current date in Datepicker在 Datepicker 中禁用距当前日期超过 2 天的日期
【发布时间】:2017-08-29 12:58:40
【问题描述】:

我正在使用 jQuery UI DatePicker。我想从当前日期起 2 天后禁用日期。我该怎么做?

$(function() {
  $("#datepicker").datepicker();
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="form-group">
  <input type="text" id="datepicker" class="form-control" />
</div>

【问题讨论】:

  • 这是一件微不足道的事情,在文档中有充分的解释......你没有读过吗?

标签: javascript jquery datepicker


【解决方案1】:

要实现这一点,您可以使用maxDate 属性。提供+2 将给出距当前值 2 天的值。试试这个:

$(function() {
  $("#datepicker").datepicker({
    maxDate: '+2'
  });
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="form-group">
  <input type="text" id="datepicker" class="form-control" />
</div>

【讨论】:

    【解决方案2】:

    您可以使用此代码:

    $(function() {
      $("#datepicker").datepicker({
        maxDate: '+2'
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 2014-04-25
      • 1970-01-01
      相关资源
      最近更新 更多