首页 > 解决方案 > 日期选择器默认日期

问题描述

我正在使用datepicker,在我的下拉菜单中,默认选择的年份是 1920,如果我选择输入值将具有的日期d/m/2020。如果我从下拉列表中选择另一年,将正常工作。问题只是如果我不改变年份。setDate也不行。

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
    (function($){
    $('.wcfm_datepicker').each(function() {
        $(this).datepicker({
            setDate: "7/11/2009",
            changeMonth: true,
            changeYear: true,
            yearRange: "1920:2010",
        });
    });
    })(jQuery);
</script>

标签: jquerydatepicker

解决方案


我找到了一个解决方案,它并不适合每个人,但对我来说它确实有效。您必须添加maxDate.

$(this).datepicker({
    changeMonth: true,
    changeYear: true,
    yearRange: "-100:-18",
    maxDate: '-18y',
});

推荐阅读