在显示之前,在jQuery UI datepicker中设置另一个月为默认值 [英] Setting another month as default in jQuery UI datepicker before display
问题描述
在我的情况下,我必须将月份设置为上一个月的默认值。
In my situation, I have to set the month to last month as default.
datepicker的默认月份是当前月份。但我希望它是上个月或其他月份作为默认显示。我该怎么做?
The default month for the datepicker is current month. But I want it to be last month or other month as default showing. How can I make it?
如:2010-09为默认值。
Such as: "2010-09" as the default.
非常感谢! >
Thank you very much!
推荐答案
您可以使用 defaultDate
选项:
You can use the defaultDate
option when creating the datepicker:
$('#date').datepicker({
defaultDate: '-2m'
});
通过传入这样的字符串,我们可以将默认日期设置为相对于当前日期的另一个日期。或者,该选项还接受 日期
对象:
By passing in a string like this we can set the default date to another one relative to the current date. Alternatively, the option also accepts a Date
object:
defaultDate: new Date(2010, 8, 1)
或与当前定义格式相同格式的字符串:
or a string in the same format as the format currently defined:
defaultDate: '1/9/2010'
以上将给您9月的默认日期。 Date
构造函数中的月份从零开始,所以8将给你9月份。
All of the above will give you a default date in September. The month in the Date
constructor starts from zero, so 8 will give you September.
这篇关于在显示之前,在jQuery UI datepicker中设置另一个月为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!