jQuery datepickerhover输出日期

我正在使用jQuery datepicker,我想显示用户当前hover的日期。 我有下面的代码(你也可以尝试JSFiddle的代码, http : //jsfiddle.net/JGM85/ ):

$(function() { $("#datepicker").datepicker(); $(".ui-state-default").live("mouseenter", function() { $("h1").text($(this).text()); }); }); 

目前,当hover在某个日期上时,日期的数量(即23)将输出到h1标签。 我想改变它,以便输出整个日期并将其存储在变量中。

任何帮助都将不胜感激。

这不是我做的最好的方式,因为我没有在jQuery UI Datepicker文档中找到任何用于获取实际日期的内容,但是在这里你去:

 $(function() { $("#datepicker").datepicker(); $(".ui-state-default").on("mouseenter", function() { $("h1").text($(this).text()+"."+$(".ui-datepicker-month",$(this).parents()).text()+"."+$(".ui-datepicker-year",$(this).parents()).text()); }); }); 

http://jsfiddle.net/JGM85/1/

第二个版本保存实际日期+之后提醒它:

 $(function() { $("#datepicker").datepicker(); $(".ui-state-default").on("mouseenter", function() { $("h1").text($(this).text()+"."+$(".ui-datepicker-month",$(this).parents()).text()+"."+$(".ui-datepicker-year",$(this).parents()).text()); var actualDate=$('h1').text(); alert(actualDate); }); }); 

http://jsfiddle.net/JGM85/2/

更新:我以前有.live作为事件处理程序,但.live没有被弃用,而.on()是要去的方法。