简体   繁体   English

如何更改日期选择器?

[英]How to change year in date picker?

I am using UIdate picker from https://jqueryui.com/datepicker/ . 我正在使用https://jqueryui.com/datepicker/中的 UIdate选择器。

My code is ok 我的代码还可以

but user who are using this UI date picker can't change current year to next year. 但是使用此UI日期选择器的用户无法将当前年份更改为明年。

In calendar it will display current date, if someone want's to go in previous year there is no any option. 在日历中,它将显示当前日期,如果有人想去上一年,则没有任何选择。

In documentation ctrl+pageup key will work, it is not working for me. 在文档ctrl + pageup键将起作用,但对我而言不起作用。

I am using same code give in date picker( https://jqueryui.com/datepicker/ ). 我正在使用相同的代码输入日期选择器( https://jqueryui.com/datepicker/ )。

Thanks In advance 提前致谢

There's a changeYear property on JQuery datepicker that you can set to true. 有一个changeYear jQuery的财产datepicker ,你可以设置为true。

$( ".selector" ).datepicker({ changeYear: true });

http://jqueryui.com/datepicker/#dropdown-month-year http://jqueryui.com/datepicker/#dropdown-month-year

This will render a select list from which you can choose the year you'd like. 这将显示一个选择列表,您可以从中选择所需的年份。

@Ataur Rahman @Ataur Ra​​hman

I need to use my code like this 我需要这样使用我的代码

$( function() { $('#reportDate').datepicker({ dateFormat: 'yy/mm/dd', changeYear: true, changeMonth: true });

You should set changeYear:true in jQuery datepicker method like this. 你应该设置changeYear:true jQuery的datepicker这样的方法。 Don't forgot to include jquery.js,datepicker.js and datepicker.css before the code snippet. 不要忘记在代码片段之前包含jquery.js,datepicker.js和datepicker.css。 see the example below. 请参阅下面的示例。

  $(function() { $('#reportDate').datepicker({ dateFormat: 'yy/mm/dd', changeYear: true }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <input type="text" id="reportDate" value=""/> 

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

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