选择/更改月/年后的jQuery UI Datepicker

Mar*_*ale 5 javascript jquery jquery-ui jquery-ui-datepicker

我想知道如何在用户选择一天或更改一个月/一年后每天运行一些代码(附加mouseenter事件)?

我试图在这些事件上附上活动

  • beforeShow
  • beforeShowDay
  • onChangeMonthYear
  • ONSELECT

在悬停时,我想在同一行中突出显示第二天(如果存在).

目前,我将moouseenter/mouseleave事件附加到创建datepicker之后的所有日期(内联).

我已经简化了我在JS小提琴中所做的事情.我需要在选择日期之后以及月/年之后更改这些事件.

JS小提琴:http://jsfiddle.net/MartinTale/Xx4GS/2/

$("div").datepicker({
    changeMonth: true,
    changeYear: true,
    inline: true,
    altField: "#datep"
});

$("tbody td:not(.ui-state-disabled, .active-calendar-cell)").mouseenter(function (e) {
    $(this).closest('td').next().find("a").addClass("hover-calendar-cell");    
    console.log('test');
});

$("tbody td:not(.ui-state-disabled)").mouseleave(function (e) {
    $("a.hover-calendar-cell").removeClass("hover-calendar-cell");
    console.log('test out');
});
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Irv*_*nin 14

您可以使用提供的jQuery datepicker事件onSelectonChangeMonthYear.

码:

$("#datep").datepicker({
    changeMonth: true,
    changeYear: true,
    onSelect: function () {
        console.log('s');
    },
    onChangeMonthYear: function () {
        console.log('o');
    }
});
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/IrvinDominin/Xx4GS/


Fun*_*bat 8

这是hacky hack.

http://jsfiddle.net/Xx4GS/3/

它起作用,第二天突出(td在这种情况下是下一个).

setTimeout是因为我认为jquery ui会破坏活动日期项,所以我们要等到我们有正确的日期项.

您可以使用onSelect而不是.change,但不是一个大问题imo

我在那里留下了一个console.log,所以你可以看到一些正在发生的事情.