简体   繁体   English

jQuery UI Datepicker-月份和年份下拉列表

[英]jQuery UI Datepicker - Month and Year Dropdown

I have the following Datepicker on my website. 我的网站上有以下Datepicker

As you can see from the example they have, it only goes as back as 2006 and as forward as 2026 on the year. 从示例中可以看到,它可以追溯到2006年,直到2026年。 I need the year to go back a lot further, how would I accomplish this? 我需要一年的时间才能回到更远的地方,我将如何实现这一目标?

Here is my code: 这是我的代码:

<script>
    $(function() {
        $("#passenger_dob").datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd/mm/yy" }).val()
    });
</script>

Use the yearRange option to set the years you want do display: 使用yearRange选项设置要显示的年份:

$("#passenger_dob").datepicker({
    changeMonth: true, 
    changeYear: true, 
    dateFormat: "dd/mm/yy",
    yearRange: "-90:+00"
});

the yearRange options can be hard-coded, or, as in my example, a range can be used relative to the current date. 可以对yearRange选项进行硬编码,或者,例如,在我的示例中,可以使用相对于当前日期的范围。 The options I've used mean "earliest year displayed is 90 years before current year" and "maximum year displayed is equal to current year". 我使用的选项表示“显示的最早年份是当前年份之前的90年”和“显示的最大年份等于当前年份”。

NB As noted in the docs, this merely affects the options displayed in the dropdown by default, it doesn't place any restriction on the dates which the user can actually enter/select. 注意:如文档所述,默认情况下,这仅影响下拉列表中显示的选项,对用户实际输入/选择的日期没有任何限制。

See http://api.jqueryui.com/datepicker/#option-yearRange for more details. 有关更多详细信息,请参见http://api.jqueryui.com/datepicker/#option-yearRange

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM