Can I make the jQuery datepicker display more year when using the changeYear option?

扶醉桌前 提交于 2019-12-20 06:23:38

问题


I am using the jQuery datepicker in an application which will be used, among other things, to insert and update birth dates of employees. I find it cumbersome to have to click several times in order to get to the 70's and 80', decades in which many employees are born in. Is there a way to access these 'further' years in less clicks? This is what my datepicker looks like

$("#DateOpened").datepicker({
    dateFormat: "mm/dd/yy",
    maxDate: "+0D",
    showAnim: 'slide',
    changeMonth: true,
    changeYear: true,
    'setDate': new Date(),
    onClose: function (selectedDate) {
        $("#DateClosed").datepicker("option", "minDate", selectedDate);
    }
});

回答1:


Use the yearRange option to increase the size of the year drop-down.

yearRange: "c-30:+0"

will allow selecting a year after 1983 in one click, and the 70's in 2 clicks.

FIDDLE

However, this isn't a good UI. When the user first clicks on the menu, it's not obvious that they can go back more than 30 years by first selecting an old year and then clicking on the menu again. You can use c-100:+0 to allow the menu to contain 100 years, hopefully this wil be enough for most users.




回答2:


If I understood correctly, then yes it is possible using minDate and maxDate options. Here you can set the year that has to be shown.

changeYear: true,
minDate: '-1Y',  //decrease 1 year from current year
maxDate: '+2Y'   //increase 2 from current year

Y represent year.

This is one shortest way to reach the year soon.



来源:https://stackoverflow.com/questions/20051887/can-i-make-the-jquery-datepicker-display-more-year-when-using-the-changeyear-opt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!