我正在开发 Web 应用程序,在此应用程序中我使用了 jquery datepicker 插件。我使用日期选择器作为内联日期选择器。当我选择一个日期时,我试图删除一个CSS类ui-state-highlight
,但没有反射(reflect)在日期选择器中。
$("#start_date").datepicker({
beforeShowDay: greySelectedDateRange,
maxDate: 0,
onSelect: function (dateText, inst) {
console.log(dateText);
var toDaysDate = getCurrrentDate('mdy'); //function returning current date
console.log(toDaysDate);
//When the selected date is equal to current date
if (dateText == toDaysDate) {
$(this).find('a.ui-state-active')
.removeClass('ui-state-highlight')
.find('.ui-datepicker-today a'));
//$(this).datepicker("refresh");
//console.log($(this));
}
}
});
当我看到控制台 console.log($(this));
时,它已被删除,但是当我检查时,css 类( ui-state-highlight
code> )仍然存在,请建议我一个解决方案。
提前致谢。
最佳答案
@Johan 和 @Stano 建议的方法有效 - 但一旦您更改月份然后返回当前月份,今天的亮点就会返回。这个细微的修改解决了这个问题:
$(function() {
$( ".datepicker" ).datepicker({
beforeShow: function(input, inst) {clearToday(inst)},
onChangeMonthYear: function(year, month, inst) {clearToday(inst)}
});
function clearToday(inst) {
setTimeout(function() {
inst.dpDiv.find('a.ui-state-highlight').removeClass('ui-state-highlight');
}, 10);
}
我发现我必须将超时减少到 10,否则当天的突出显示会短暂闪烁并可见。
关于jquery datepicker 删除 .ui-state-highlight 类 onSelect 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690626/