这段代码以前可以工作,但现在不行了,它只获取数组中的第一个值...
var unavailableDates
是一个停止在日期选择器上显示日期的数组。
有什么想法吗?
由于某种原因,它没有循环遍历数组中的所有日期!?!?
var unavailableDates = ["4-7-2011","5-7-2011"];
function unavailable(date) {
var dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == 0) {
return [false, "", "Unavailable"];
} else {
var day = date.getDay();
return [(day != 0 && day != 2 && day != 3 && day != 4 && day != 6)];
}
}
$(function(){
$('#smh').datepicker({
showOn: "both",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
beforeShowDay: unavailable,
minDate: -0,
dateFormat: "dd/mm/yy",
onSelect: function(e) {
e = e.split('/')[1] + '/' + e.split('/')[0] + '/' + e.split('/')[2];
var date = new Date(e);
var day = date.getDay(); // 0 = sunday etc...
if (day === 1) {
$("#check2").hide();
$("#text").hide();
$("#check1").show();
} else if (day === 5) {
$("#check1").hide();
$("#text").hide();
$("#check2").show();
}
$("#bdate").html(this.value);
}
})
最佳答案
在 jQuery 中,当在 array
中找不到 elem
时,$.inArray(elem, array)
方法返回 -1,而不是 0 >。
所以我认为你应该使用:
if ($.inArray(dmy
, 不可用日期) == -1)
而不是:
if ($.inArray(dmy, unavailableDates) == 0)
关于javascript - Jquery Datepicker,束手无策,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6440542/