2

我想知道当现在是星期五时,如何禁用下星期一。我可以在每个星期一禁用,但我只想禁用一个,当一天是星期五,只有第一个星期一,而不是每个星期一。

我正在使用它,我正在进入 if 循环,但它没有返回任何内容。

minDate: new Date(y,m,fridayNotMonday),

function fridayNotMonday() 
{
  var vdate = new Date();
  var vday = vdate.getDay();
  var vm = vdate.getMonth(), vd = vdate.getDate(), vy = vdate.getFullYear();
  var vd1 = vdate.getDate() + 2;
  var vd2 = vdate.getDate() + 4;

  if (vday == 5) {
    alert("friday");
    firstDate: new Date(vy,vm,vd2);
    return firstDate
  } else {
    firstDate1: new Date(vy,vm,vd1);
    return firstDate1;
  }
}
4

1 回答 1

0

您应该使用日期选择器的beforeShowDay选项

var now = new Date();
var day = now.getDay();
// on the following line 5 means friday. Days start counting from 0=sunday to 6=saturday.
// so if now is friday then find the date of the following monday
var disabled = (day===5)? new Date(now.getFullYear(), now.getMonth(), now.getDate()+3): null;

$('#datepickerelement').datepicker({
    beforeShowDay:function(current){
        // if the disabled date we calculate is the same as the one the plugin tries to show
        // then set its selectable status to false..
        if (disabled !== null && disabled.getTime() === current.getTime() ) {
            return [false];
        } else {
            return [true];
        }

    }
});

演示在 http://jsfiddle.net/r6QUd/2/

于 2012-10-09T09:23:01.423 回答