最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery UI Datepicker - Month and Year Dropdown - Stack Overflow

programmeradmin5浏览0评论

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 acplish this?

Here is my code:

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

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 acplish this?

Here is my code:

<script>
    $(function() {
        $("#passenger_dob").datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd/mm/yy" }).val()
    });
</script>
Share Improve this question edited Dec 22, 2017 at 15:32 Ganesh Yadav 2,6852 gold badges33 silver badges52 bronze badges asked Sep 21, 2016 at 12:34 BroadbizBroadbiz 251 gold badge1 silver badge7 bronze badges 3
  • Once you select 2006 as the year , the range of the selection bees 1996 - 2016 .So you can keep going back by selecting the lowest year – Webdev Commented Sep 21, 2016 at 12:38
  • api.jqueryui./datepicker/#option-yearRange – ADyson Commented Sep 21, 2016 at 14:03
  • Hi there, I understand that but this is not what I want. I want the years up to around the 1930s to be on the drop down straight away. – Broadbiz Commented Sep 21, 2016 at 15:10
Add a ment  | 

1 Answer 1

Reset to default 10

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".

N.B. 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./datepicker/#option-yearRange for more details.

发布评论

评论列表(0)

  1. 暂无评论