在JQuery UI中动态更改选项DatePicker失败

时间:2022-06-02 20:33:38

I want to make date range selection using jquery-ui datepicker. First change at #dteStart succeed to set minDate at #dteEnd. But #dteEnd failed to refresh its options on next change, if i alert DateOptions.minDate its value changed according to dateMin.

我想使用jquery-ui datepicker进行日期范围选择。 #dteStart的第一次更改成功将#DteEnd设置为minDate。但是#dteEnd在下次更改时无法刷新其选项,如果我提醒DateOptions.minDate其值根据dateMin更改。

Maybe i miss something here...

也许我想念一下......

$(document).ready(function () 
{
    $("#dteStart").datepicker()
    .change(function () 
    {
        dateStart = $(this).datepicker('getDate');
        dateMin = new Date(dateStart.getTime());
        dateMin.setDate(dateMin.getDate() + 1);

        var DateOptions = {
            dateformat: "mm/dd/yyyy",
            minDate: dateMin
        }
        $("#dteEnd").datepicker(DateOptions);
    });
});

TIA,

REV

3 个解决方案

#1


26  

put $("#dteEnd").datepicker("destroy"); before $("#dteEnd").datepicker(DateOptions); and it will work fine.

把$(“#dteEnd”)。datepicker(“destroy”);在$(“#dteEnd”)之前.datepicker(DateOptions);它会工作正常。

#2


17  

If you just want to change the already configured options, you can also do:

如果您只想更改已配置的选项,还可以执行以下操作:

$("#dteEnd").datepicker("option", DateOptions);

or

$("#dteEnd").datepicker("option", { dateFormat: "mm/dd/yyyy" });

#3


2  

The following jQuery helper function may be useful in such cases to preserve the original options:

在这种情况下,以下jQuery帮助器函数可能非常有用,可以保留原始选项:

$.fn.customizeDatepicker = function(newOptions) {
    var prevOptions = $(this).datepicker('option', 'all');
    $(this).datepicker('destroy').datepicker($.extend(prevOptions, newOptions));
    return this;
};

It saves the previous options and extends them with the new options.

它保存以前的选项并使用新选项扩展它们。

#1


26  

put $("#dteEnd").datepicker("destroy"); before $("#dteEnd").datepicker(DateOptions); and it will work fine.

把$(“#dteEnd”)。datepicker(“destroy”);在$(“#dteEnd”)之前.datepicker(DateOptions);它会工作正常。

#2


17  

If you just want to change the already configured options, you can also do:

如果您只想更改已配置的选项,还可以执行以下操作:

$("#dteEnd").datepicker("option", DateOptions);

or

$("#dteEnd").datepicker("option", { dateFormat: "mm/dd/yyyy" });

#3


2  

The following jQuery helper function may be useful in such cases to preserve the original options:

在这种情况下,以下jQuery帮助器函数可能非常有用,可以保留原始选项:

$.fn.customizeDatepicker = function(newOptions) {
    var prevOptions = $(this).datepicker('option', 'all');
    $(this).datepicker('destroy').datepicker($.extend(prevOptions, newOptions));
    return this;
};

It saves the previous options and extends them with the new options.

它保存以前的选项并使用新选项扩展它们。