我是 javascript 新手,我想创建一个日期选择器,使用带有日期列表的 json 响应突出显示某些日期。
这就是我正在尝试的:
var dates = [];
dates = getDays();
$(function () {
$("#datepicker").datepicker({
beforeShowDay: setHoliDays
});
function setHoliDays(date) {
for (var i = 0; i < dates.lenght; i++) {
if (dates[i] == date) {
return [true, "green"];
}
}
return [true, ""];
}
});
function getDays() {
var arr = [];
$.getJSON("/getDates", function (data) {
$.each(data, function (id, val) {
arr.push(val);
});
return arr;
});
}
JSON 响应是这样的:
["2013-03-18T12:00:00","2013-03-19T12:00:00","2013-03-20T12:00:00",
"2013-03-21T11:00:00","2013-03-21T10:00:00","2013-03-21T08:00:00",
"2013-03-25T10:00:00","2013-03-26T08:00:00","2013-03-27T09:00:00",
"2013-03-28T08:00:00","2013-03-28T09:00:00","2013-03-28T10:00:00",
"2013-03-28T11:00:00","2013-03-28T12:00:00"]
我究竟做错了什么?