gpt4 book ai didi

javascript - Jquery Datepicker,束手无策

转载 作者:行者123 更新时间:2023-11-28 21:20:53 25 4
gpt4 key购买 nike

这段代码以前可以工作,但现在不行了,它只获取数组中的第一个值...

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com