Jquery datepicker years change

后端 未结 5 1999
小蘑菇
小蘑菇 2021-02-11 22:57

I am using datepicker of jquery for a field to set date of birth, while default picker is displayed which gives option to scroll to date monthly and sounds tedious. Is there a w

相关标签:
5条回答
  • 2021-02-11 23:24

    Insert changeYear: true on your DataPicker parameter.

    Example :

    $(function() {
            $( ".datepicker" ).datepicker({
                changeMonth: true,
                changeYear: true
            });
        });
    
    0 讨论(0)
  • 2021-02-11 23:36

    There's a changeYear property on the datepicker that you can set to true.

    $( ".selector" ).datepicker({ changeYear: true });
    

    http://jqueryui.com/datepicker/#dropdown-month-year

    This will render a select list from which you can choose the year you'd like.

    0 讨论(0)
  • 2021-02-11 23:38

    Set changeYear: true, as shown in sample code below:

     $("#birth_date").datepicker({
                dateFormat: 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                maxDate: '-1D'
            },
            $.datepicker.regional["fr"]
        );
    

    Refer here for more options: https://jqueryui.com/datepicker/

    0 讨论(0)
  • 2021-02-11 23:39

    changeYear property lets you enable a year dropdown. Also might be helpful to use yearRange property to control number of years they see in the dropdown, by default it's from -10 to +10 years.

    $('#date').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-40:+40"
    });
    

    Details from original documentation:

    The range of years displayed in the year drop-down: either relative to today's year ("-nn:+nn"), relative to the currently selected year ("c-nn:c+nn"), absolute ("nnnn:nnnn"), or combinations of these formats ("nnnn:-nn"). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.

    0 讨论(0)
  • 2021-02-11 23:42

    You can enable a year dropdown by using the 'changeYear' property (see: jQuery UI) from the datepicker object.

    0 讨论(0)
提交回复
热议问题