jQuery UI Datepicker - 禁用特定日期 [英] jQuery UI Datepicker - Disable specific days
问题描述
是否有任何(简单的)方法可以设置 jQuery UI Datepicker 以禁止选择特定的、预定的日期?
Is there any (easy) way to set the jQuery UI Datepicker to disallow selection of specific, predetermined days?
我能够获得 这种方法有效,但是,它会产生一个空错误,从而阻止它在 IE 中显示.
I was able to get this approach working, however, it produces a null error which prevents it from displaying in IE.
'natDays[...].0' 为空或不是对象
'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屋!