admin管理员组

文章数量:1290263

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.

i'am using

jquery-ui-datepicker.min.js

as a plugin for my calendar

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.

i'am using

jquery-ui-datepicker.min.js

as a plugin for my calendar

Share Improve this question edited Feb 15, 2013 at 8:44 Darren 70.8k24 gold badges140 silver badges145 bronze badges asked Feb 15, 2013 at 8:27 telexpertelexper 2,44110 gold badges39 silver badges66 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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

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

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

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.

本文标签: javascriptjquery ui datepicker go to today buttonStack Overflow