【问题标题】:Disable specific day of specific months in jQuery datepicker在 jQuery datepicker 中禁用特定月份的特定日期
【发布时间】:2018-10-10 07:45:49
【问题描述】:

使用 jQuery Datepicker 禁用特定月份(即 5 月 1 日至 9 月 28 日)的特定日期(即星期日 - 星期五仅启用星期六)。

对于其余的日期(9 月 29 日 - 4 月 30 日)应该允许选择所有工作日。

【问题讨论】:

标签: jquery jquery-ui datepicker jquery-ui-datepicker


【解决方案1】:

你可以使用这个:https://api.jqueryui.com/datepicker/#option-beforeShowDay

仅启用星期六的示例:

<input />

$('input').datepicker({
    beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [(date.getDay()==6)?1:0]
    }
});

编辑 1:

$('input').datepicker({
    beforeShowDay: function(date){
                var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        if((date.getMonth()<4) || (date.getMonth()>=8)){
            if(date.getMonth()==8 && date.getDate()<28){
            return[0];
          } else {
            return [1];
          } 
        } else {
            return [(date.getDay()==6)?1:0];
        }

    }
});

【讨论】:

  • @gsmio83 正确。但我只在 5 月 1 日到 9 月 28 日期间需要它。
猜你喜欢
  • 1970-01-01
  • 2017-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
  • 2010-10-15
  • 1970-01-01
  • 2015-07-31
相关资源
最近更新 更多