选择/更改月/年后的jQuery UI Datepicker [英] jQuery UI Datepicker after select/change month/year

查看:81
本文介绍了选择/更改月/年后的jQuery UI Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanted to find out how I can run some piece of code (attach mouseenter event) for every day after user has selected a day or changed a month/year?

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

I have tried to attach the event on these events


  • beforeShow

  • beforeShowDay

  • onChangeMonthYear

  • onSelect

  • beforeShow
  • beforeShowDay
  • onChangeMonthYear
  • onSelect

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

On hover I want to highlight next day in the same row if it exists.

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

Currently I attach moouseenter/mouseleave event to all days after datepicker is created (which is inline).

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

I have simplified what I'm doing in the JS fiddle below. I need to have those events working after a date is selected and after month/year has been changed.

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');
});

提前致谢。

推荐答案

这是hacky hack。

Here is hacky hack.

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

它有效,第二天突出显示(下一个 td 在这种情况下)。

It works, highlights the next day( the next td in this case).

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

setTimeout is because I think jquery ui destroys the active date item, so we wait until we have the right one.

您可以使用 onSelect 而不是 .change ,但不能一个大不了的事情

You might be able to use onSelect instead of .change, but not a big deal imo

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

I left a console.log in there so you can see a little bit of whats going on.

这篇关于选择/更改月/年后的jQuery UI Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆