简体   繁体   中英

jQuery UI Datepicker - Month and Year Dropdown

I have the following Datepicker on my website.

As you can see from the example they have, it only goes as back as 2006 and as forward as 2026 on the year. 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:

$("#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. The options I've used mean "earliest year displayed is 90 years before current year" and "maximum year displayed is equal to current year".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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