【发布时间】:2016-01-19 15:13:56
【问题描述】:
我有以下几点:
$("<style>")
.prop("type", "text/css")
.html("\
#markDates {\
color: #FF0000;\
}")
.appendTo("head");
然后我调用这个类:
$('#multidatepicker').multiDatesPicker({
//onClose: function (value, date) {
// //debugger;
// date.dpDiv.find('.ui-state-default').css('background-color', 'rgb(153, 204, 153)')
//},
numberOfMonths: [3, 4],
//addDisabledDates: HolidayList,
addDates: getHolidays(),
beforeShowDay: function (date) {
// console.log('dateIn?', $.inArray(date, HolidayList));
if ($.inArray(date, HolidayList) !== -1) {
$("td").removeClass("ui-state-highlight");
return [true, "markDates" , "This is a holiiday"];
}
else {
return [true];
}
}
});
当我运行它然后检查突出显示的日期元素时,会发现以下内容:
<td class=" ui-state-highlight undefined " data-handler="selectDay" data-event="click" data-month="0" data-year="2016"><a class="ui-state-default" href="#">1</a></td>
为什么 markDates 未定义?我尝试过:
removeClass("ui-state-highlight").addClass("markDates")
结果相同。
【问题讨论】:
-
#markDates在第一个脚本中是一个id。而removeClass("ui-state-highlight").addClass("markDates")正在添加类markDates -
您已将最后一个右括号
//}注释掉为beforeShowDay -
@Filipe 感谢您的更改。我进行了适当的更改,但仍然在元素中显示为未定义。
-
“这是一个假期”也不会显示为工具提示。
-
它可能碰到了
if ... else块的else 部分,并试图将类设置为beforeShowDay返回值的第二个索引。那是未定义的。我敢打赌,如果您将return [true];更改为return [true, 'noMarkDates'];,它将不再是未定义的,但它的类将是 noMarkDates。
标签: javascript jquery-ui-datepicker