jQuery UI Datepicker - 如果今天是星期一,请禁用今天的日期? [英] jQuery UI Datepicker - disable today's date if today is Monday?

查看:105
本文介绍了jQuery UI Datepicker - 如果今天是星期一,请禁用今天的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery UI Datepicker:

jQuery UI Datepicker:

您好,

我正在尝试弹出日历仅允许选择将来的星期一日期。我试过这个代码:

I'm trying to have the pop-up calendar allow only the Monday dates in the future to be selected. I've tried this code:

$(function() {
    $('#dateWeekly').datepicker({
        showOn: 'both', // use to enable calendar button and focus 
        buttonImage: 'childtime/images/calendar.gif',
        buttonImageOnly: true,
        buttonText: 'Show Calendar',
        numberOfMonths: 3,
        showButtonPanel: true,
        minDate: -0, maxDate: '+12M',
        // beforeShowDay: function(date){ return [date.getDay() == 1,""]}
        beforeShowDay: function(date) { return [date.getDay() == 1, "" && date.getTime() != today.getTime(), ""]; }
    });
});

这将禁用所有过去的日期,并禁用除了星期一(迄今为止很好)之后的所有将来的日子,但是如果今天是星期一,它无法禁用今天的日期。任何建议将不胜感激。谢谢!

This disables all past dates, and disables all future days except Mondays (so far so good), but it fails to disable today's date if today is Monday. Any suggestions will be appreciated. Thanks!

推荐答案

下面的代码可能是这个问题的解决方案。

Below Code might be the solution for this question.

    beforeShowDay: function(date) { 
          returnFlag = true;    
              currentDate = new Date();
          if( date.getDay() == 1 && date.getDate() == currentDate.getDate()  
                                 && date.getMonth() == currentDate.getMonth()){
                returnFlag = false;
          }
          return [returnFlag,'',false];

    }

这篇关于jQuery UI Datepicker - 如果今天是星期一,请禁用今天的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆