问题
$("#div-calendar").datepicker({ onSelect: SelectedDay });
function SelectedDay(date, inst) {
var s = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class");
alert(s);
}
Im trying to get the class of the clicked date/cell.
The Problem is the Event happens BEFORE the class change, so it will always show me the classes of the previous click. I would need "OnSelected" instead.. any ideas?
回答1:
An ugly hack I've resorted to using in the past:
$("#div-calendar").datepicker({ onSelect: SelectedDay });
function SelectedDay(date, inst) {
// HACK: the ui hasn't been updated yet, check later
window.setTimeout(function() {
var s = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class");
alert(s);
}, 0);
}
来源:https://stackoverflow.com/questions/4854635/jquery-datepicker-onselect-event-fired-too-early