jquery datepicker之后setDate不再能够更改月和年的标题 [英] jquery datepicker after setDate no longer able to change Month and Year in the header
问题描述
我正在使用JQuery UI Datepicker来选择日期。
我在初始化时将changeMonth和changeYear设置为true。
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 );
}
});
但是我想要默认设置datepicker,所以我在设置之前使用了 setDate of changeMonth and changeYear:
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?
提前感谢您的帮助!
推荐答案
我尝试过您使用的相同脚本。它适用于我。检查此 http://jsfiddle.net/XE68u/
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')
这篇关于jquery datepicker之后setDate不再能够更改月和年的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!