我有一個字段需要使用日期選擇器輸入日期。我曾嘗試和搜索的錯誤(未顯示)如何顯示日期選擇器
這裏是我的日期選擇器腳本
<script>
$(function(){
$('.date-picker').datepicker({
dateFormat: "yy-mm",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
function isDonePressed(){
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()){
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)).trigger('change');
$('.date-picker').focusout()//Added to remove focus from datepicker input box on selecting date
}
},
beforeShow : function(input, inst) {
inst.dpDiv.addClass('month_year_datepicker')
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length-4, datestr.length);
month = datestr.substring(0, 2);
$(this).datepicker('option', 'defaultDate', new Date(year, month-1, 1));
$(this).datepicker('setDate', new Date(year, month-1, 1));
$(".ui-datepicker-calendar").hide();
}
}
})
});
</script>
這是我在HTML領域:
<table>
<tr>
<td style="width:150px;text-align:center; background-color:#f9f9f9";>From Date</td>
<td style="background-color:#f9f9f9";><input style="width:150px;text-align:center" class="date-picker" name="oec_month1" ></td>
<td style="width:150px;text-align:center; background-color:#f9f9f9";>To Date</td>
<td style="background-color:#f9f9f9";><input style="width:150px;text-align:center" class="date-picker" name="oec_month2" ></td>
</tr>
</table>
字段不顯示日期選擇器。請幫忙!
三江源。我已經包含了JqueryUI的庫。我的日期選擇器不顯示,因爲我包含錯誤的庫。感謝您回答我的問題 – NHH
沒問題。真高興你做到了。如果有幫助,不要忘記接受答案。 –