简体   繁体   English

jQuery Datepicker 问题与 minDate 和 maxDate

[英]jQuery Datepicker issues with minDate & maxDate

Currently I am using the following code in order to setting the Date picker functionality -目前我正在使用以下代码来设置日期选择器功能 -

$("#datepicker").click(function() {
        $(this).datepicker().datepicker( "show" );
});

But if I remove the "show" from parameter.但是如果我从参数中删除“show”。 it doesn't work and I want to add some more parameters like minDate , maxDate .它不起作用,我想添加更多参数,例如minDatemaxDate

Please help How can I do it with "show" parameter.请帮助我如何使用“show”参数来做到这一点。

Thanks in advance!!提前致谢!!

You can pass it as an options like您可以将其作为选项传递,例如

$("#datepicker").click(function () {
    $(this).datepicker({
        maxDate: yourMaxDate,
        minDate: yourMinDate
    }).datepicker("show");
});

I don't know why you are using a click handler to initialize the datepicker.... you can just do我不知道你为什么使用点击处理程序来初始化日期选择器......你可以这样做

$("#datepicker").datepicker({
    maxDate: yourMaxDate,
    minDate: yourMinDate
});

Demo: Fiddle演示:小提琴


After the plugin initialization, if you want to update the value of options, you can use the option method插件初始化后,如果要更新options的值,可以使用option方法

$("#datepicker").datepicker('option', 'optioname', optionvalue)

you can change using option您可以更改使用option

$("#datepicker").click(function() {
    $(this).datepicker('option', 'minValue', new Date(startDate));
    $(this).datepicker('option', 'maxValue', new Date(endDate));
}

or...
    $("#datepicker").click(function() {
    $(this).datepicker('option', { minValue: new Date(startDate),
                                      maxValue: new Date(endDate) });

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM