【问题标题】:Date-picker - How to disable one monday only?日期选择器 - 如何仅禁用一个星期一?
【发布时间】:2012-09-29 13:32:54
【问题描述】:

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

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

【问题讨论】:

  • This 可能会有所帮助
  • This 可能会帮助您解决问题。它看起来与您的问题重复,但有多个日期,因此它应该为解决您的问题提供一些指导

标签: jquery jquery-plugins datepicker


【解决方案1】:

您应该使用日期选择器的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/

【讨论】:

    猜你喜欢
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多