jQuery UI Datepicker - 禁用特定日期 [英] jQuery UI Datepicker - Disable specific days

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

问题描述

有没有(容易)的方式设置jQuery UI Datepicker以禁止选择具体的预定日期?

Is there any (easy) way to set the jQuery UI Datepicker to disallow selection of specific, predetermined days?

我能够得到这种方法

I was able to get this approach working, however, it produces a null error which prevents it from displaying in IE.


'natDays [...]。0'是null或不是一个对象

'natDays[...].0' is null or not an object

提前感谢!

更新:如果我包含一些代码,可能有帮助吗?无论如何,大部分是从上述线程中直接得到的:

UPDATE: Might help if I included some code, right? Anyway, most of this was taken straight from the aforementioned thread:

natDays = [
        [7, 23], [7, 24], [8, 13], [8, 14], 
    ];

    function nationalDays(date) {
        for (i = 0; i < natDays.length; i++) {
            if (date.getMonth() == natDays[i][0] - 1
            && date.getDate() == natDays[i][1]) {
                return [false, natDays[i][2] + '_day'];
            }
        }
        return [true, ''];
    }

    function noWeekendsOrHolidays(date) {
        var noWeekend = $.datepicker.noWeekends(date);
        if (noWeekend[0]) {
            return nationalDays(date);
        } else {
            return noWeekend;
        }
    }


    $(function() { 
        $("#datepicker").datepicker({
            inline: true,
            minDate: new Date(2009, 6, 6), 
            maxDate: new Date(2009, 7, 14), 
            numberOfMonths: 2, 
            hideIfNoPrevNext: true,
            beforeShowDay: $.datepicker.noWeekends,
            altField: '#alternate',
        }); 
    });

再次感谢

推荐答案

您是否尝试使用前面的'var'关键字正确声明natDays?

Have you tried declaring natDays properly with the 'var' keyword in front?

另外 - 您的natDays结尾有一个逗号定义。

Also - you have an extra comma at the end of your natDays definition.

natDays [i] [2]将无法正常工作,因为您的数组只包含2个项目 - 尝试只是''

natDays[i][2] won't work as your the arrays only have 2 items in them - try just ''

此外,您还需要正确设置您的beforeShowDay函数名称 - 看起来不像调用自定义函数

Additionally, you'll want to set your beforeShowDay function name correctly - doesn't look like it's even calling your custom function

这篇关于jQuery UI Datepicker - 禁用特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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