jQuery datepicker years shown

后端 未结 8 1309
一向
一向 2020-12-13 01:51

With the jQuery datepicker, how does one change the year range that is displayed? On the jQuery UI site it says the default is \"10 years before and after the current year

8条回答
  •  醉酒成梦
    2020-12-13 01:56

    Perfect for date of birth fields (and what I use) is similar to what Shog9 said, although I'm going to give a more specific DOB example:

    $(".datePickerDOB").datepicker({ 
        yearRange: "-122:-18", //18 years or older up to 122yo (oldest person ever, can be sensibly set to something much smaller in most cases)
        maxDate: "-18Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
        minDate: "-122Y"
    });
    

    Hope future googlers find this useful :).

提交回复
热议问题