datepicker格式化时间

只选择年份:

$("#txttYear").datepicker({
changeMonth: false,
changeYear: true,
showButtonPanel: true,
dateFormat: '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));
}
});

 

选择年月:

$("#txtYearMonth").datepicker({
changeMonth: false,
changeYear: true,
showButtonPanel: true,
dateFormat: 'yymm',
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));
}
});

选择年月日:

$("#txtDate").datepicker({
changeMonth: false,
changeYear: true,
showButtonPanel: true,
dateFormat: 'yymmdd',
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));
}
});

 

posted @ 2013-05-19 10:39  快活杰  阅读(1335)  评论(0编辑  收藏  举报