有這麼個需求,datepicker默認是選某個具體的日子的,可是如今只選到年月爲止,
solution:
html以下:
<div>
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" class="date-picker" />
</div>
在datepicker中配置以下:
html
$('.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)); } });
在style裏添加這麼一句:
.ui-datepicker-calendar {
display: none;
}
ui