Change option dynamically in JQuery UI DatePicker fails

前端 未结 3 959
Happy的楠姐
Happy的楠姐 2020-12-11 02:12

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 ne

相关标签:
3条回答
  • 2020-12-11 02:25

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

    $.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.

    0 讨论(0)
  • 2020-12-11 02:31

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

    0 讨论(0)
  • 2020-12-11 02:44

    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" });
    
    0 讨论(0)
提交回复
热议问题