使用beforeShowDay和对象数组在jQuery datepicker中排除日期 [英] Excluding dates in the jQuery datepicker using beforeShowDay and an array of objects
本文介绍了使用beforeShowDay和对象数组在jQuery datepicker中排除日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象数组,什么是确定日期是否在数组中的最佳方法,因此无法在jQuery日期选择器中选择日期.如果需要,我可以将DateValue存储为日期.
I have an array of objects, what is the best way to determine if a date is in the array so it cannot be selected in the jQuery date picker. If needed, I can store DateValue as a date.
var EventDates = [{"DateID: "1", DateValue: "3/1/2011", FormattedDate: Tue, Mar 1 2011"},
{"DateID: "2", DateValue: "3/2/2011", FormattedDate: Wed, Mar 2 2011"}]
$('.juidateicon_ext').datepicker({
showOn: "button",
buttonImage: "/Content/images/icons/calendar.gif",
buttonImageOnly: true,
showOn: 'both',
beforeShowDay: eventDays
});
function eventDays(date) {
1. Code to determine if "date" is in DateValue in the EventDates Array
2. If date exist, return [false, ""];else return [true, ""];
}
推荐答案
我随意清理了EventDates
数组:
var EventDates = [{
"DateID": "1",
"DateValue": "3/1/2011",
"FormattedDate": "Tue, Mar 1 2011"},
{
"DateID": "2",
"DateValue": "3/2/2011",
"FormattedDate": "Wed, Mar 2 2011"
}];
这是eventDays
函数:
function eventDays(date) {
var length = EventDates.length, i = 0;
var event = null, eventDate = false;
while (i < length && !eventDate) {
event = EventDates[i];
eventDate = new Date(event.DateValue).valueOf() === date.valueOf();
i++;
}
return [!eventDate, ''];
}
这是一个有效的示例: http://jsfiddle.net/andrewwhitaker/uYpnW/1/
Here's a working example: http://jsfiddle.net/andrewwhitaker/uYpnW/1/
希望有帮助!
这篇关于使用beforeShowDay和对象数组在jQuery datepicker中排除日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文