我想顯示一個datepicker只顯示像這個Q'jquery date picker to show month year only這樣的月份+年菜單,這不是一個問題,但我有問題以下如何設置datepicker的日期只顯示月份和年份
我想輸入文本加載日期的字符串值,如01/2011,我希望在focusin事件datepicker將加載顯示的日期,我的意思是我希望它打開與2011年和01月已經選定,
但由於某些原因,當我點擊文本輸入原始日期「01/2011」更改爲「01/01/2011」
這裏是我的代碼領先
$(document).delegate("#timeSpanFrom, #timeSpanTo", "focusin", function() {
var $this = $(this);
var inputDate = $.datepicker.parseDate('dd/mm/yy', "01/"+$this.val());
if (!$this.data('datepicker_enabled')) {
$this.datepicker({
changeMonth : true,
changeYear : true,
showButtonPanel : true,
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));
$(".ui-datepicker-calendar").hide();
}
});
$this.datepicker({ dateFormat: 'mm/yy' });
$this.datepicker('setDate', inputDate);
$this.data('datepicker_enabled',true);
}
});
$(document).delegate("#timeSpanFrom, #timeSpanTo", "focus", function() {
$(".ui-datepicker-calendar").hide();
});
感謝
則可以創建一個的jsfiddle? – 2012-01-30 17:24:22
那麼,您是否希望datepick在彈出窗口中顯示月份和年份,或者與當前月份中的日期一起顯示? – Cheery 2012-01-30 18:12:53
@SérgioMichels:不能做jsfiddle atm:/ @Cheery:我很喜歡彈出窗口(隱藏日子)我希望輸入字段只顯示月/年而不是日/月/年輸入字段以及從日期選擇器中選擇日期 – Daniel 2012-01-30 18:26:47