jQuery datepicker year dropdown starts from 1900 and I want it to start from the bottom [duplicate]

寵の児 提交于 2019-12-24 07:34:42

问题


I am using jQuery datepicker on my website and I have it set like this:

$( "#datepicker" ).datepicker( 
    { 
        dateFormat: 'mm/dd/yy',  
        changeMonth: true, 
        changeYear: true,  
        yearRange: "1900:-13" 
    } 
).on('change', function() {
    $(this).valid();  // triggers the validation test
    // '$(this)' refers to '$("#datepicker")'
}); 

So my year select bar enables years 1900 and up to 2004.

By default when opening the year selectbox - it starts from 1900 and I have to scroll a lot for a more relevant year.

How can I set my jQuery datepicker to start from 2004 (scrolling up) and not from 1900 (scrolling a lot down)?

Researching this issue leads to old posts (7 years ago) and I might be able to find a more practical solution that works for these days.


回答1:


You can try this option:

$( ".selector" ).datepicker({
    currentText: "Now"
});

I think that modifying currenText value you can achieve what you want.

API docs



来源:https://stackoverflow.com/questions/42650410/jquery-datepicker-year-dropdown-starts-from-1900-and-i-want-it-to-start-from-the

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