简体   繁体   English

在jQuery UI Datepicker上仅显示月份

[英]Showing only month on jquery ui datepicker

I created a datepicker using jquery ui only showing months but it wasn't as I expect I don't want to list months on select I want to list them like this datepicker - if you going to click When you will see the list 我使用jquery ui创建了一个仅显示月份的datepicker,但并非如我所愿,我不想在选择时列出月份,我想像此datepicker一样列出它们-如果要单击的话,您将看到该列表

 $(document).ready(function(){ $(".monthPicker").datepicker({ dateFormat: 'mm-yy', changeMonth: true, changeYear: true, showButtonPanel: true, 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).val($.datepicker.formatDate('yy-mm', new Date(year, month, 1))); } }); $(".monthPicker").focus(function () { $(".ui-datepicker-calendar").hide(); $("#ui-datepicker-div").position({ my: "center top", at: "center bottom", of: $(this) }); }); }); 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <label for="month">Month: </label> <input type="text" id="month" name="month" class="monthPicker" /> 

If you don't mind, you can add some css to your page: 如果您不介意,则可以在页面中添加一些CSS:

.ui-datepicker-year{
    display:none !important;
}

And pre-handle the output of the datepicker if needed. 并在需要时预先处理日期选择器的输出。

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

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