【问题标题】:jquery datepicker get the date on mouseover from the celljquery datepicker 从单元格中获取鼠标悬停的日期
【发布时间】:2011-01-31 04:30:44
【问题描述】:

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

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

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

我还找到了this 代码。但对我来说真的不起作用。 任何帮助表示赞赏。

提前致谢。

【问题讨论】:

    标签: jquery datepicker mouseover


    【解决方案1】:
    var month = $(this).closest('.ui-datepicker').find('.ui-datepicker-month').text();
    var year  = $(this).closest('.ui-datepicker').find('.ui-datepicker-year').text();
    

    【讨论】:

    【解决方案2】:

    就像 Yoda 提到的那样,您将希望使用 live 方法将事件附加到文档上,以便任何与选择器匹配的已创建元素的行为方式相同。

    你会得到这样的结果:

    <h1></h1>
    
    <label for="pickDate"/>
    <input type="text" id="pickDate"/>
    
    $(function() {
        $("#pickDate").datepicker();
        $(".ui-state-default").live("mouseenter", function() {
            $("h1").text($(this).text());
        });
    });
    

    jsfiddle 上的示例

    【讨论】:

    • 谢谢,很高兴您将示例上传到 jsFiddle!
    【解决方案3】:

    日历是在 DOM 准备好之后制作的,所以除非你使用这样的方法,否则它永远不会起作用:

    http://api.jquery.com/live/

    【讨论】:

      猜你喜欢
      • 2014-07-09
      • 2013-03-07
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多