jQuery UI Datepicker仅启用阵列中的特定日期 [英] jQuery UI Datepicker enable only specific days in array
本文介绍了jQuery UI Datepicker仅启用阵列中的特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图禁用datepicker中的所有日期,并且仅启用数组中的日期。这是我迄今为止的代码 http://jsfiddle.net/peter/yXMKC/ 的问题只有5月14日显示为启用。其他人都被禁用。有任何想法吗?
I am trying to disable all dates in a datepicker and only enable dates which are in an array. This is the code I have so far http://jsfiddle.net/peter/yXMKC/ the problem is only May 14th shows up as enabled. The others are all disabled. Any ideas?
var availableDates = ["9-5-2011","14-5-2011","15-5-2011"];
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) == 1) {
return [true, "","Available"];
} else {
return [false,"","unAvailable"];
}
}
$('#date').datepicker({ beforeShowDay: available });
推荐答案
$。inArray(dmy,availableDates)返回索引的元素,所以当你与1比较只有14-5-2011将匹配。检查不等于-1。应该工作。
$.inArray(dmy, availableDates) returns the index of the element, so when you compare with 1 only 14-5-2011 will match. Check for not equal to -1. Should work.
小提琴 - http:// jsfiddle。 net / yXMKC / 4 /
var availableDates = ["9-5-2011","14-5-2011","15-5-2011"];
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
console.log(dmy+' : '+($.inArray(dmy, availableDates)));
if ($.inArray(dmy, availableDates) != -1) {
return [true, "","Available"];
} else {
return [false,"","unAvailable"];
}
}
这篇关于jQuery UI Datepicker仅启用阵列中的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文