jquery datepicker after setDate no longer able to change Month and Year in the header

不羁岁月 提交于 2019-12-11 10:57:23

问题


I'm using the JQuery UI Datepicker to pick date. I set "changeMonth" and "changeYear" to true at the initialization.

$( "#from" ).datepicker({
  defaultDate: "+1w",
  changeMonth: true,
  changeYear: true,
  dateFormat: 'yy-mm-dd',
  onClose: function( selectedDate ) {
    $( "#to" ).datepicker( "option", "minDate", selectedDate );
  }
});
$( "#to" ).datepicker({
  defaultDate: "+1w",
  changeMonth: true,
  changeYear: true,
  dateFormat: 'yy-mm-dd',
  onClose: function( selectedDate ) {
    $( "#from" ).datepicker( "option", "maxDate", selectedDate );
  }
});

But I want the datepicker to be set by default, so I used setDate BEFORE THE SETTING of changeMonth and changeYear:

$(#from).datepicker('setDate', '10-10-2010');
$(#to).datepicker('setDate', '10-10-2011');

This was successful. However, in the dropdown calendar on the header I could no longer directly change month and year.

Does anyone know what's happened or know the solution to this? Or I should rather change another way to set Date?

Thanks in advance for your help!


回答1:


I tried the same script that you have used. It works for me.Check this http://jsfiddle.net/XE68u/

 $( "#from" ).datepicker({
  defaultDate: "+1w",
  changeMonth: true,
  changeYear: true,
  dateFormat: 'yy-mm-dd',
  onClose: function( selectedDate ) {
    $( "#to" ).datepicker( "option", "minDate", selectedDate );
  }
});
$( "#to" ).datepicker({
  defaultDate: "+1w",
  changeMonth: true,
  changeYear: true,
  dateFormat: 'yy-mm-dd',
  onClose: function( selectedDate ) {
    $( "#from" ).datepicker( "option", "maxDate", selectedDate );
  }
});

$("#from").datepicker('setDate', '10-10-10')
$("#to").datepicker('setDate', '11-10-10')


来源:https://stackoverflow.com/questions/14525436/jquery-datepicker-after-setdate-no-longer-able-to-change-month-and-year-in-the-h

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