【问题标题】:Limit days selection to non past current month only in Bootstrap Datepicker仅在 Bootstrap Datepicker 中将天数选择限制为非过去当前月份
【发布时间】:2013-11-20 03:16:25
【问题描述】:

我正在使用bootstrap-datepicker,我需要将其配置为仅允许从当前日期到当前月份的结束日期进行选择,我不想让用户在几个月中导航,这可能吗?如何?我阅读了文档,但没有发现任何真正有用的内容

【问题讨论】:

    标签: jquery twitter-bootstrap datepicker


    【解决方案1】:

    1) 您可以使用引导日期选择器的 startDateendDate 选项。

    2) 在 startDate 中设置今天的日期

    var today = new Date();
    

    3) 要获取本月的最后一天,请使用此方法

    var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
    

    终于

    var today = new Date(); //Get today's date
    var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);  //To get the last date of today's month
    $("#datepicker").datepicker({
        startDate: today,
        endDate: lastDate
    });
    

    JSFiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-28
      • 2018-10-24
      • 2021-05-22
      • 1970-01-01
      相关资源
      最近更新 更多