禁用特定月份的JqueryUI datepicker [英] Disable specific months JqueryUI datepicker

查看:123
本文介绍了禁用特定月份的JqueryUI datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含jQuery UI Datepicker的预订表单,现在我有一个主要的问题需要我帮助:有些旅行仅在某些日子有效,并且只能在某些月份出售,因为例如飓风季节.

I'm creating a booking form that includes jQuery UI Datepicker, now i have a main issue that I need help with: Some trips will have only certain days active, and can only be sold certain months because, for example cyclone season.

禁用特定工作日的功能可以正常工作,但是我不确定如何停用完整的月份,例如十月.是否有可能?

The function to disable specifc weekdays works perfect, but i'm not sure how can I deactivate complete months for example October. Is it possible?

任何建议都将对您有所帮助,这是我的代码,请让我知道是否应该更好地解释我的问题,或者是否应该添加代码的其他部分.预先感谢!

Any advices will be helpful, here is my code, please let me know if should I explain better my question, or if should I add some other parts of my code. Thanks in advance!

$.datepicker.setDefaults( $.datepicker.regional[ getLanguage() ] );

$( "#booking" ).datepicker({
   showOn: "button",
   dateFormat : 'yy/mm/dd',
   buttonText: "Select",
   beforeShowDay: disableSpecificWeekDays,
   changeMonth: true,
   changeYear: true,
   minDate: 0
}
);

// 0 = monday, 1 = tuesday, 2 = wednesday, 3 = thursday, 4=friday, 5 = saturday, 6=sunday
var daysToDisable = [1, 4, 6];

function disableSpecificWeekDays(date) {
            var day = date.getDay();
            for (i = 0; i < daysToDisable.length; i++) {
                if ($.inArray(day, daysToDisable) != -1) {
                    return [false];
                }
            }
            return [true];
 }

例如,使用此代码,我可以停用特定的日期,但是要停用整个月,我需要写下每个日期,在某些情况下,我需要停用至少三或四个月每次旅行.

With this code for example i'm being able to deactivate specific dates, but to deactivate a whole month i'll need to write each date, and in certain cases, i'll need to deactivate at least three or four months for each trip.

var $disableMonths = new Array("2013/10/01","2013/10/02","2013/10/03", "...");

function disableSpecificMonths(mydate){
var $return = true;
var $returnclass ="available";

$checkdate = $.datepicker.formatDate('yy/mm/dd', mydate);

    for(var i = 0; i < $disableMonths.length; i++) {
            if($disableMonths[i] == $checkdate) {
                $return = false;
                $returnclass= "unavailable";
            }
    }

return [$return,$returnclass];

}

但是,如果不可能取消激活一个完整的月份,我将很想了解如何将这两个功能混合使用,因此,我将取消激活特定的工作日和特定日期.

But also, if it's not possible to deactivate a complete month i'll love to get some ideas on how can I mix this two functions, so i'll be deactivating specific Week Days and Specific Dates.

推荐答案

您可以将禁用功能"更新为以下内容:

You can update your "disable function" to something like this:

var daysToDisable = [1, 4, 6];
var monthsToDisable = [9];

function disableSpecificWeekDays(date) {
    var day = date.getDay();
    if ($.inArray(day, daysToDisable) != -1) {
        return [false];
    }

    var month = date.getMonth();
    if ($.inArray(month, monthsToDisable) != -1) {
        return [false];
    }
    return [true];
}

这篇关于禁用特定月份的JqueryUI datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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