2011-01-31 102 views
1

我想要将鼠标悬停在日期上。一个小型的盒子会出现并显示一些与该日期相关的数据。当鼠标在日历上方运行时。我需要鼠标运行的日期,这样我才能够调用正确的值来显示在div框中。下面的代码显示了从单元格收集的日期。但我需要包括月份和年份的完整日期。jquery datepicker从单元格获取鼠标悬停的日期

$('.ui-state-default').mouseover(function(){ 

    var a= $(this).text(); 
    alert(a); 
}); 

而且也是我发现this代码。但对我而言并不真正。 任何帮助表示赞赏。

在此先感谢。

回答

3
var month = $(this).closest('.ui-datepicker').find('.ui-datepicker-month').text(); 
var year = $(this).closest('.ui-datepicker').find('.ui-datepicker-year').text(); 
+1

工作,如果你没有一个以上的NUMBEROFMONTHS。如果你有,我为它写了一个代码片段:http://browse-tutorials.com/snippet/get-date-mouseover-cell-jquery-ui-datepicker – ram4nd 2012-05-14 12:04:16

2

就像尤达提到你将要使用的活方法将事件附加到文档上,以便与选择器相匹配的任何已创建元素的行为方式都相同。

你最终会像这样的东西:

<h1></h1> 

<label for="pickDate"/> 
<input type="text" id="pickDate"/> 

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

例如在jsfiddle

+0

非常感谢,你上传了jsFiddle的样本! – 2013-01-23 08:51:00