jQuery datepicker 禁用每周除一个以外的所有日期

jQuery datepicker disable all dates per week but one

我想选择一个日期,假设我选择一个星期一,我想只能在另一个日期选择器上选择星期一并禁用所有其他日期,换句话说,我想选择一个时间间隔两个日期选择器之间相隔 7 天。

我怎样才能做到这一点?

我试过这个:

beforeShowDay: function(date) {
  console.log('beforeShowDay');
  var day = date.getDay();
  return [day != day, ''];
},

但不确定它是否应该工作或我应该将函数放置在哪个日期选择器中。

更新:

var curday = "";
var unavailableDays = [];
var dateselected = "";

function ViewDay(date) {
    dmy = date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getFullYear();
    day = date.getDay();
    if (date > dateselected) {
        if ($.inArray(day, unavailableDays) == -1) {
            return [false, "", "Unavailable"];
        } else {
            return [true, ""];
        }
    } else {
        return [false, "", "Unavailable"];
    }
}

$('#startdatesahasrara').datepicker({
    dateFormat: 'dd/mm/yy',
    minDate: 3,
    onSelect: function(e) {

        $('#enddatesahasrara').removeData("hasqtip");
        $('#enddatesahasrara').removeAttr("data-hasqtip");
        $('#enddatesahasrara').qtip("destroy", true);
        $('#enddatesahasrara').removeAttr('title');

        $('#enddatesahasrara').val('');
        unavailableDays = [];
        dateselected = new Date(e);
        curday = new Date(e).getDay();
        unavailableDays.push(curday);
        console.log('trigger');
    }
});

$("#enddatesahasrara").datepicker({
    dateFormat: 'dd/mm/yy',
    showAnim: "slideDown",
    minDate: 0,
    beforeShowDay: ViewDay
});

希望对您有帮助!

var curday = "";
var unavailableDays = [];
var dateselected = "";
$('.datepicker1').datepicker({
  dateFormat: 'yy-mm-dd',
  onSelect: function(dateText) {
    $('.datepicker').val('');
    unavailableDays = [];
    dateselected = new Date(dateText);
    curday = new Date(dateText).getDay();
    unavailableDays.push(curday);
  }
});

$(".datepicker").datepicker({
  dateFormat: 'yy-mm-dd',
  showAnim: "slideDown",
  minDate: 0,
  beforeShowDay: ViewDay //$.datepicker.noWeekends
});


function ViewDay(date) {
  dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
  day = date.getDay();
  if (date > dateselected) {
    if ($.inArray(day, unavailableDays) == -1) {
      return [false, "", "Unavailable"];
    } else {
      return [true, ""];
    }
  } else {
    return [false, "", "Unavailable"];
  }
}
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>

<input type="text" class="datepicker1" />
<input type="text" class="datepicker" />