jquery ui datepicker转到今天的按钮

时间:2022-11-30 09:35:40

i need my calendar to go to the current date when [today] button is clicked, so that the user can get to the current day when browsing my calendar.

当点击[今天]按钮时,我需要我的日历转到当前日期,这样用户可以在浏览我的日历时到达当天。

for example the current month is feb 2013 and the user is browsing on the dec 2015 page of the calendar when he clicks the [today] button it will automatically return to the current days page of the calendar which is feb 2013.

例如,当前月份是2013年2月,并且当用户点击[今天]按钮时,用户正在浏览日历的2015年12月页面,它将自动返回到日历的当前日期页面,即2013年2月。

i'am using

jquery-ui-datepicker.min.js

as a plugin for my calendar

作为我日历的插件

2 个解决方案

#1


1  

You could do:

你可以这样做:

function TodaysDate() {
 var currentTime = new Date()
 var month = currentTime.getMonth() + 1
 var day = currentTime.getDate()
 var year = currentTime.getFullYear()

 return month + "/" + day + "/" + year;
}

$("#btnToday").click(function() {
  var today = new Date();
  $(target).datepicker('setDate', TodaysDate()); 
} 

Where target is your date picker control ID.

目标是您的日期选择器控件ID。

#2


7  

The jQuery UI Datepicker has functionality built into it for this.

jQuery UI Datepicker具有内置功能。

See this: http://jqueryui.com/datepicker/#buttonbar

请参阅:http://jqueryui.com/datepicker/#buttonbar

$(function() {
    $( "#datepicker" ).datepicker({
        showButtonPanel: true
    });
});

#1


1  

You could do:

你可以这样做:

function TodaysDate() {
 var currentTime = new Date()
 var month = currentTime.getMonth() + 1
 var day = currentTime.getDate()
 var year = currentTime.getFullYear()

 return month + "/" + day + "/" + year;
}

$("#btnToday").click(function() {
  var today = new Date();
  $(target).datepicker('setDate', TodaysDate()); 
} 

Where target is your date picker control ID.

目标是您的日期选择器控件ID。

#2


7  

The jQuery UI Datepicker has functionality built into it for this.

jQuery UI Datepicker具有内置功能。

See this: http://jqueryui.com/datepicker/#buttonbar

请参阅:http://jqueryui.com/datepicker/#buttonbar

$(function() {
    $( "#datepicker" ).datepicker({
        showButtonPanel: true
    });
});