此循环遍历每月的每个选定日期,但不会突出显示每个月的所有选定日期,而是首先突出显示。 请查看并建议更好的方法或纠正它以便正常工作。
for (var eachDate = 0; eachDate < selectedArrayLength; eachDate++)
{
if (ind == new Date(selected[eachDate]).getMonth())
{
var selectedDates = {};
selectedDates[new Date(selected[eachDate])] = new Date(selected[eachDate]);
var highlightMe = new Array();
highlightMe.push(new Date(selected[eachDate]));
console.log(highlightMe);
line.datepicker({ disabled: false, defaultDate: d, beforeShowDay: function (dateToHighlight)
{
var Highlight = selectedDates[dateToHighlight];
if (Highlight)
{
return [true, "Highlighted", Highlight];
}
else
{
return [true, '', ''];
}
}
});
}
以下是此循环测试运行的日志。
"calendar0" Multi.html:135
Array [ Date 2015-01-01T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-01-08T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-01-15T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-01-22T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-01-29T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-01-29T19:00:00.000Z ] Multi.html:160
"calendar1" Multi.html:135
Array [ Date 2015-02-05T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-02-12T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-02-19T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-02-26T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-02-26T19:00:00.000Z ] Multi.html:160
"calendar2" Multi.html:135
Array [ Date 2015-03-05T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-03-12T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-03-19T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-03-26T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-03-26T19:00:00.000Z ] Multi.html:160
"calendar3" Multi.html:135
Array [ Date 2015-04-02T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-04-09T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-04-16T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-04-23T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-04-23T19:00:00.000Z ] Multi.html:160
"calendar4" Multi.html:135
Array [ Date 2015-04-30T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-05-07T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-05-14T19:00:00.000Z ] Multi.html:144
Array [ Date 2015-05-14T19:00:00.000Z ] Multi.html:160