简体   繁体   English

在jquery UI datepicker中增加日期选项的范围

[英]Increase range of date options in jquery UI datepicker

I'm using jquery's datepicker for users to select their DOB. 我正在使用jquery的datepicker供用户选择其DOB。 I set the default to 01/01/1980 so that its a little easier to select your DOB (our constraint is that your age > 18 years. 我将默认值设置为1980年1月1日,以便选择DOB更加容易(我们的限制是您的年龄> 18岁。

I set minDate to be 100 years in the past from today. 我将minDate设置为从今天开始的100年。 When I toggle the datepicker, the minimum date appears to be 1970. If I select it, close the datepicker, and open it again, I can go further back (to select 1960 for example). 当我切换日期选择器时,最小日期似乎是1970。如果选择它,请关闭日期选择器,然后再次打开它,我可以再往回走(例如选择1960)。 I would like to allow users to select a date preceding 1970 without having to do this. 我想允许用户选择1970年之前的日期,而不必这样做。

1970年受约束

Code: 码:

$(function() {
  $( "#id_date_of_birth" ).datepicker({
    changeMonth: true,
    changeYear: true,
    maxDate: "-18Y",
    minDate: "-100Y",
    defaultDate: '01/01/1980'
   });
 });

It looks like the range cap happens to be about an 18 year split. 范围上限似乎恰好是18年的分割。
That might be related to your maxDate 那可能与您的maxDate

Try omitting the maxDate or increasing it to see if you're still capped at 1970 on the first opening of the dropdown. 尝试省略maxDate或增加它,以查看下拉菜单首次打开时是否仍处于1970年的上限。

If that works, you can play with your defaultDate and maxDate to get the desired range. 如果maxDate ,您可以使用defaultDatemaxDate来获得所需的范围。

From the Docs: 从文档中:

maxDate 的maxDate

The maximum selectable date. 最大可选日期。 When set to null, there is no maximum. 设置为null时,没有最大值。 Multiple types supported: 支持多种类型:

Date: A date object containing the maximum date. 日期:包含最大日期的日期对象。

Number: A number of days from today. 数量:从今天开始的天数。 For example 2 represents two days from today and -1 represents yesterday. 例如2代表从今天起两天,-1代表昨天。

String: A string in the format defined by the dateFormat option, or a relative date. 字符串:采用dateFormat选项定义的格式的字符串或相对日期。 Relative dates must contain value and period pairs; 相对日期必须包含值和期间对; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. 有效期限为“ y”代表几年,“ m”代表几个月,“ w”代表几周,“ d”代表几天。 For example, "+1m +7d" represents one month and seven days from today. 例如,“ + 1m + 7d”表示从今天起一个月零七天。

http://api.jqueryui.com/datepicker/#option-maxDate http://api.jqueryui.com/datepicker/#option-maxDate

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

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