最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I programmatically change the selected month in JQuery datepicker - Stack Overflow

programmeradmin3浏览0评论

I have a jQuery datepicker and I cannot figure out how to programmatically change the month back to the current month. After making a POST request to save the user's dates I need to return the calendar back to the current month. The calendar may be on a different month from the user playing around with different dates. I have tried setting the mindate again but that did not work.

This is not a popup calendar.

I have a jQuery datepicker and I cannot figure out how to programmatically change the month back to the current month. After making a POST request to save the user's dates I need to return the calendar back to the current month. The calendar may be on a different month from the user playing around with different dates. I have tried setting the mindate again but that did not work.

This is not a popup calendar.

Share Improve this question edited Jan 25, 2014 at 1:08 Johnston asked Jan 25, 2014 at 1:00 JohnstonJohnston 20.9k22 gold badges75 silver badges123 bronze badges 3
  • how do you submit your form? normally direct submit or ajax? – Rami.Q Commented Jan 25, 2014 at 1:04
  • @Rami.Q I use ajax. This is why I am having the issue. Because the state does not change. – Johnston Commented Jan 25, 2014 at 1:05
  • then on ajax success do setDate as adeneo wrote in the answer – Rami.Q Commented Jan 25, 2014 at 1:15
Add a ment  | 

2 Answers 2

Reset to default 13

Setting the datepicker back to today

$('#myDatePicker').datepicker('setDate', new Date());

setting just the month back

var date = $('#myDatePicker').datepicker('getDate');

date.setMonth( (new Date()).getMonth() );

$('#myDatePicker').datepicker('setDate', date);

FIDDLE

You can also use .val() to set the date

$("#datepicker").val(date);
发布评论

评论列表(0)

  1. 暂无评论