JQuery datepicker 允许用户设置年份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8413036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:30:45  来源:igfitidea点击:

JQuery datepicker allow user to set the year

jqueryjquery-uijquery-ui-datepicker

提问by sandrozbinden

I am using the datepicker jquery plugin with the settings below.

我正在使用具有以下设置的 datepicker jquery 插件。

$("#date").datepicker({
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    showOtherMonths: true,
    selectOtherMonths: true 
});

Now what i want to do is allowing the user to set the year. I mean by manual changing the input of the selection drop down.

现在我想做的是允许用户设置年份。我的意思是手动更改选择下拉菜单的输入。

Is there any setting to do that ?

是否有任何设置可以做到这一点?

The reason I would like to do that is because I don't know, if the user is selecting a date from the year 1920 or 2220 or what ever year. So I don't have a good default date value. And the dropdown interface isn't that userfriendly if you have to click 20 times to get from the year 2000 to the year 1600.

我想这样做的原因是因为我不知道用户是从 1920 年还是 2220 年或任何一年中选择一个日期。所以我没有一个好的默认日期值。如果你必须点击 20 次才能从 2000 年到 1600 年,那么下拉界面不是那么用户友好。

Edit: What I want to do is the "Show unlimited years:" from keith-wood.name/datepick.html#monthyear. Is there anything similar with the standard jquery datepicker. I can't find the setting yearRange: 'any' in the jquery datepicker documentation.

编辑:我想要做的是来自 keith-wood.name/datepick.html#monthyear 的“显示无限年:”。有没有与标准的 jquery datepicker 类似的东西。我在 jquery datepicker 文档中找不到设置 yearRange: 'any' 。

回答by Sebastian

You can specify a range of years by adding

您可以通过添加指定年份范围

yearRange: "1930:2010"

to your attributes. For example:

到你的属性。例如:

 $( "#datepicker" ).datepicker({
     changeMonth: true,
     changeYear: true,
     yearRange: "1930:2010"
 });

回答by ggzone

changeYear: true

already displaying a selectbox.. so whats the problem?? for manually input of the year just create own input text?

已经显示了一个选择框..有什么问题吗??手动输入年份只需创建自己的输入文本?

回答by Rokan Nashp

You can set year and also month just putting following two lines.

您可以设置年份和月份,只需放置以下两行即可。

$("#date").datepicker({
    changeMonth: true,
    changeYear: true
});

Here dateis input ID

这里日期是输入ID