jquery datepicker get the date on mouseover from the cell

谁都会走 提交于 2019-12-08 08:41:17

问题


I want to get the date on mouse over. A small div-box will appear and display some data related with that date. when mouse is running over the calendar. I need the date where the mouse is running so I will be able to call right values to display in the div-box. The code below show the date gathering from the cell. But I need full date including month and year.

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

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

And also I found this code. But does not really work for me. Any help is appreciated.

Thanks in advance.


回答1:


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



回答2:


Just like Yoda mentioned you will want to use the live method to attach the event on the document so any created elements that match the selector behave the same way.

You will end up with something like this:

<h1></h1>

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

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

Example on jsfiddle




回答3:


The calendar is made after the DOM is ready, so that will never work unless you use a method like this :

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



来源:https://stackoverflow.com/questions/4847646/jquery-datepicker-get-the-date-on-mouseover-from-the-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!