jquery datetimepicker今天禁用

时间:2015-07-18 07:57:17

标签: jquery datetimepicker

我想允许选择除今天以外的所有周末(如果今天是周末)。但是,以下代码允许选择今天。这就是我想要的:

  jQuery('.datetimepicker').datetimepicker({
    timepicker:false,
    minDate:'+1970/01/01',
    maxDate:'+1970/01/10',
    defaultDate:'+1970/01/01',
    format:'d/m/Y',
    beforeShowDay: DisableWeekDays,
    closeOnDateSelect: true
 });

 function weekendsOnly(date) {
    var day = date.getDay();
    return [(day > 0 && day < 6), ''];
}

function DisableWeekDays(date) {
    var weekenddate = weekendsOnly(date);
    var disableweek = [!weekenddate[0]];
    return disableweek;
}

这就是我正在使用的内容:http://xdsoft.net/jqplugins/datetimepicker/ 此外,minDate似乎根本不起作用。

1 个答案:

答案 0 :(得分:0)

试试这个 - minDate = tomorrow.setDate(today.getDate() - 1);

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() - 1);

$("#minDate").datepicker({
    showOn: "none",
    minDate: tomorrow,
    dateFormat: "DD dd-mm-yy",
    onSelect: function(dateText) {
        minDateChange;
    },
    inputOffsetX: 5,
});

如果有效,请告诉我。我没有尝试过。 您的代码可能类似于:

 var today = new Date();
 var tomorrow = new Date();
  today.setDate(today.getDate() - 1);
  jQuery('.datetimepicker').datetimepicker({
    timepicker:false,
    minDate:'+1970/01/01',
    maxDate:today,
    defaultDate:'+1970/01/01',
    format:'d/m/Y',
    beforeShowDay: DisableWeekDays,
    closeOnDateSelect: true
 });

 function weekendsOnly(date) {
    var day = date.getDay();
    return [(day > 0 && day < 6), ''];
}

function DisableWeekDays(date) {
    var weekenddate = weekendsOnly(date);
    var disableweek = [!weekenddate[0]];
    return disableweek;
}