http://jsfiddle.net/e31m02L9/2/
如何让DateTimePicker选择一个月而不是日期和时间? (因此值为YYYY-MM
)
查看在线文档,我被告知使用startView
:
$('#datetimepickerday').datetimepicker({
startView: "month"
});
但它会出现以下错误:
答案 0 :(得分:1)
是的,您必须使用viewMode
代替startView
,并将format
选项设置为YYYY-MM
。如果您使用eonasdan datetimepicker指定format: 'YYYY-MM'
,则默认行为是显示月份下拉列表(无需明确设置viewMode
)
这是一个工作示例:
$('#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>
&#13;