【问题标题】:How to disable previous dates while still displaying the previous dates?如何在仍显示以前日期的同时禁用以前的日期?
【发布时间】:2013-05-21 12:17:09
【问题描述】:

我使用了“minDate : dateToday”和“minDate : 0”,但没有显示上一个日期。

例如,如果我输入今天的日期,当明天检查时,数据库仍然有昨天的日期,但显示的日期将是明天的。

我该如何解决这个问题?

使用的代码

$('#startDate,#endDate,#dateEntered').datepicker({
        minDate : dateToday,
        maxDate : "+10Y",
        buttonImage: "static/images/calender.gif",
        buttonImageOnly: true,
        constrainInput: true
    }); 

【问题讨论】:

  • 你可以先发布一些代码。
  • 您所描述的行为正如我所理解的那样正是我期望 datepicker 工作的方式。如果你能提供一个样本,也许我能更好地理解你在找什么。

标签: jquery datepicker jquery-ui-datepicker


【解决方案1】:

我遇到了同样的问题。我不得不使用日期选择器的 beforeShowDay option 并删除 mindDate 选项。

像这样初始化:

$('#startDate,#endDate,#dateEntered').datepicker({
        maxDate : "+10Y",
        buttonImage: "static/images/calender.gif",
        buttonImageOnly: true,
        constrainInput: true,
        beforeShowDay: function(date) { 

           if (date != previousDate && date < dateToday) { //you will need to save the previous date in a variable
               return [false, "", "Date Unavailable"];
           }               
           return [true, ""];
        }
    }); 

【讨论】:

    【解决方案2】:

    工作演示--&gt;http://jsfiddle.net/f6qJF/1/

    $('#date').datepicker({
        maxDate : "+10Y",
        buttonImage: "static/images/calender.gif",
        buttonImageOnly: true,
        constrainInput: true,
        beforeShowDay: check
    });
    
    function check(date) {
        if (date > new Date()) return [true];
        else return [false];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      相关资源
      最近更新 更多