Jquery datepicker 年更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7388923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:46:55  来源:igfitidea点击:

Jquery datepicker years change

jqueryjquery-uidatepicker

提问by Sankalp

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 way by which I can change years directly rather using months to change the year in turn.

我正在使用 jquery 的日期选择器作为字段来设置出生日期,同时显示默认选择器,它提供了每月滚动到日期的选项,听起来很乏味。有没有一种方法可以直接更改年份,而不是使用月份依次更改年份。

回答by Jamie Dixon

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

changeYear日期选择器上有一个属性,您可以将其设置为true

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

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

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

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

这将呈现一个选择列表,您可以从中选择您想要的年份。

回答by Guilherme de Jesus Santos

Insert changeYear: trueon your DataPicker parameter.

插入changeYear: true您的 DataPicker 参数。

Example :

例子 :

$(function() {
        $( ".datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
    });

回答by Fokwa Best

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

设置changeYear: true,如下面的示例代码所示:

 $("#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/

有关更多选项,请参阅此处:https: //jqueryui.com/datepicker/

回答by Bas Slagter

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

您可以使用 datepicker对象中的“changeYear”属性(请参阅:jQuery UI)启用年份下拉列表。