use*_*142 3 javascript jquery jquery-ui-datepicker
我正在使用jQuery datepicker,我想显示用户当前悬停的日期.我有下面的代码(你也可以尝试JSFiddle的代码,http://jsfiddle.net/JGM85/):
$(function() {
$("#datepicker").datepicker();
$(".ui-state-default").live("mouseenter", function() {
$("h1").text($(this).text());
});
});
Run Code Online (Sandbox Code Playgroud)
目前,当悬停在某个日期上时,日期(即23)的数量将输出到h1标签.我想改变它,以便输出整个日期并将其存储在变量中.
任何帮助都将不胜感激.
这不是我做的最好的方式,因为我在jQuery UI Datepicker文档中找不到获取实际Date的任何内容,但是在这里你去:
$(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());
});
});
Run Code Online (Sandbox Code Playgroud)
第二个版本保存实际日期+之后提醒它:
$(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);
});
});
Run Code Online (Sandbox Code Playgroud)
更新:我之前有.live作为事件处理程序但是.live没有被弃用,而.on()是要去的方法.