jQuery DatePicker OnSelect Event Fired too early

我们两清 提交于 2019-12-11 15:47:22

问题


$("#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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!