【问题标题】:Disabled the past dates in datepicker and selected only "monday"禁用日期选择器中的过去日期并仅选择“星期一”
【发布时间】:2017-03-02 06:20:20
【问题描述】:

我的输入文本框中有这个日期选择器,它在日期选择器中运行良好,并且也只有选定的。我的问题是想禁用过去的日期,并且只禁用未来选定的日期“星期一”。下面是我的代码

<input type='text' name='datepicker' id='datepicker' placeholder='Date:' class='form-control'>
$(function() {
    $("#datepicker").datepicker({
        beforeShowDay: function (date) {
            //getDate() returns the day (0-31)
            if (date.getDay() == 1 ) {
                return [true, ''];
            }
            return [false, ''];
        }
    });
});

我的代码发生的情况是选择了星期一,但没有禁用过去的日期。有人可以帮我弄清楚如何禁用过去的日期吗?TIA

【问题讨论】:

  • 看起来您正在使用特定的日期选择器库并询问如何使用该库,因此您应该说出您正在使用的特定库(+版本) .
  • 我认为是新的

标签: php jquery wordpress datepicker


【解决方案1】:

试试这个... 通过mindate=0;

$(function() {
    $("#datepicker").datepicker({
        minDate:0,
        beforeShowDay: function (date) {
            //getDate() returns the day (0-31)
            if (date.getDay() == 1 ) {
                return [true, ''];
            }
            return [false, ''];
        }
    });
});

【讨论】:

  • 我将在哪里添加 maxdate=0 ?
  • 在日期选择器中如果你想要未来的日期然后minDate=0,如果你想要过去的日期然后maxDate=0
【解决方案2】:

设置minDate : new Date,

$(function() {
   $("#datepicker").datepicker({
    set minDate : new Date,
    beforeShowDay: function (date) {
        //getDate() returns the day (0-31)
        if (date.getDay() == 1 ) {
            return [true, ''];
        }
        return [false, ''];
    }
 });
});

【讨论】:

  • 您好,请澄清一下?设置 minDate : 新日期,上面没有`?
  • 这是日期选择器设置。设置 minDate 新日期,将从今天开始日期。
猜你喜欢
  • 2016-07-03
  • 2021-04-15
  • 2020-03-17
  • 1970-01-01
  • 2021-01-11
  • 2013-03-23
  • 2012-09-29
  • 2018-10-16
  • 1970-01-01
相关资源
最近更新 更多