日期选择器 - 如何仅禁用一个星期一?

时间:2012-10-09 08:56:59

标签: jquery jquery-plugins datepicker

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

我正在使用它,我进入了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;
  }
}

1 个答案:

答案 0 :(得分:0)

您应该使用datepicker的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/