简体   繁体   English

jQuery UI datepicker功能仅选择年份或年份-月份或年份-月份-日期

[英]jQuery UI datepicker functionality to select only year or year-month or year-month-date

I'm using jQuery UI plugin for datepicker and I need some features in it. 我将jQuery UI插件用于datepicker,并且其中需要一些功能。 I want users to be able to select date in following three formats: 我希望用户能够以以下三种格式选择日期:

  • User can select only year. 用户只能选择年份。
  • User can select year and month. 用户可以选择年份和月份。
  • User can select year, month and date from calendar. 用户可以从日历中选择年,月和日期。

Last one is obviously simple that user can select any date from calendar, I can also made datepicker to display year and month like below: 最后一个显然很简单,用户可以从日历中选择任何日期,我也可以使日期选择器显示年和月,如下所示:

$(function() {
$('.date-picker').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'MM yy',
    onClose: function(dateText, inst) { 
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
    }
});
});

http://jsfiddle.net/bopperben/DBpJe/ http://jsfiddle.net/bopperben/DBpJe/

But I can't find any way to achieve all above point together in same datepicker. 但是我找不到在同一日期选择器中共同实现上述所有目标的任何方法。 If this is not possible in this plugin can you suggest me any other plugin which is user friendly. 如果在此插件中无法做到这一点,那么您可以建议我其他任何用户友好的插件。 Thanks! 谢谢!

Telerik's Kendo UI datepicker plugin you can use. 您可以使用Telerik的Kendo UI datepicker插件。 It has many functionality and can be easily customized. 它具有许多功能,可以轻松自定义。

Also found this link, which might help you http://www.telerik.com/forums/date-picker-setting-for-selecting-only-month-and-year 还找到了此链接,可能会帮助您http://www.telerik.com/forums/date-picker-setting-for-selecting-only-month-and-year

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

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