如何在jquery日期选择器上禁用“明天只”?

时间:2017-09-25 03:25:34

标签: jquery jquery-ui datepicker

你好我的新jquery datepicker。我需要明天在jquery datepicker中禁用。以下是js脚本:

$(function() {
    $("#iDate").datepicker();
});

它只是一个没有任何选项的普通jquery datepicker脚本。 Here is the fiddle

2 个答案:

答案 0 :(得分:1)

您可以使用解决方案http://jsfiddle.net/JjPrU/1392/



$(function() {
  var d = new Date();
  var unavailableDate = (d.getDate() + 1) + "-" + (d.getMonth() + 1) + "-" + d.getFullYear();
  var unavailableDates = [];
  unavailableDates.push(unavailableDate);

  function unavailable(date) {
    dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
    if ($.inArray(dmy, unavailableDates) == -1) {
        return [true, ""];
    } else {
        return [false, "", "Unavailable"];
    }
  }

  $(function() {
    $("#iDate").datepicker({
        dateFormat: 'dd MM yy',
        beforeShowDay: unavailable
    });
  });
});

<link href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/themes/black-tie/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min.js"></script>
<input id="iDate">
&#13;
&#13;
&#13;

希望这会对你有所帮助。

答案 1 :(得分:0)

您可以使用流动的代码。 Demo

var d = new Date();
var unavailableDate = [(d.getDate() + 1) + "-" + (d.getMonth() + 1) + "-" + d.getFullYear()];
function unavailable(date) {
    dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
    if ($.inArray(dmy, unavailableDate) == -1) {
        return [true, ""];
    } else {
        return [false, "", "Unavailable"];
    }
}

$(function() {
    $("#iDate").datepicker({
        defaultDate: new Date(),
        dateFormat: 'dd MM yy',
        beforeShowDay: unavailable
    });

});
相关问题