繁体   English   中英

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

[英]jQuery UI Datepicker after select/change month/year

我想知道如何在用户选择一天或更改一个月/一年后每天运行一些代码(附加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');
});

提前致谢。

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

码:

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

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

这是hacky hack。

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

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

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

您可以使用onSelect而不是.change ,但不是很重要的imo

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

有一个名为“onSelect”的事件,其日期为其参数。 看这个例子:

$("#datePicker").datepicker({
    //the format
    dateFormat: "dd/mm/yy",
    //called when date is selected
    onSelect: function (date) {
        alert(date);
    }
});

Cou可以在api-doc中找到所有细节: http//api.jqueryui.com/datepicker/#option-onSelect

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM