简体   繁体   English

Bootstrap DateTimePicker-选择月份(YYYY-MM格式)

[英]Bootstrap DateTimePicker - choose Month (YYYY-MM format)

http://jsfiddle.net/e31m02L9/2/ http://jsfiddle.net/e31m02L9/2/

How can I have DateTimePicker pick a month instead of a date and time? 如何让DateTimePicker选择月份而不是日期和时间? (So the value is YYYY-MM ) (因此值为YYYY-MM

Looking at online documentation I was told to use startView : 查看在线文档,我被告知要使用startView

$('#datetimepickerday').datetimepicker({
    startView: "month"
});

But it gives the following error: 但是它给出了以下错误:

在此处输入图片说明

Yes, you have to use viewMode instead of startView and set format option to YYYY-MM . 是的,您必须使用viewMode而不是startView并将format选项设置为YYYY-MM If you specify format: 'YYYY-MM' with eonasdan datetimepicker the default behaviour is to show the months dropdown (no need to explicitly set viewMode ) 如果您使用eonasdan datetimepicker指定format: 'YYYY-MM' ,则默认行为是显示月份下拉列表(无需显式设置viewMode

Here a working example: 这是一个工作示例:

 $('#datetimepicker1').datetimepicker({ format: 'YYYY-MM', viewMode: 'months' }); 
 <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/> <link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script> <div class="input-group date" id="datetimepicker1"> <input type="text" class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> 

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

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