我有这个日期选择器和onChangeMonthYear函数,但是问题是选择时月份是12-1。 我该如何更改? 谢谢
$("#monthPicker").datepicker({
dateFormat: 'MM/yy',
changeMonth: true,
changeYear: true,
showButtonPanel: false,
//showAnim: "slideDown",
onChangeMonthYear: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
//minDate: new Date(year, month - 1, 1);
//maxDate: new Date(year, month - 1, 1);
$(this).val($.datepicker.formatDate('MM/yy', new Date(year, month, 1)));
//$(this).datepicker('setDate', new Date(year, month, 1));
$(this).datepicker('refresh');
}
});
答案 0 :(得分:0)
<div class="line col-sm-3">
<div class="form-group">
<label>Month picker</label>
<input type="text" class="form-control monthpicker input-sm" >
</div>
<script>
$(function(){
$(".monthpicker").datepicker({
autoclose: true,
minViewMode: 1,
format: 'MM'
}).on('changeDate', function(selected){
startDate = new Date(selected.date.valueOf());
startDate.setDate(startDate.getDate(new Date(selected.date.valueOf())));
$('.monthpicker').datepicker('setStartDate', startDate);
});
});
</script>