1

I am using jQuery datepicker for selecting date. But I need the date to be displayed like "April 2012". To achieve this I added the following option to the datepicker code

$(function() {
    $('#a').datepicker({
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'MM yy',
    });
});

After doing this, lets say I select "1st Jan, 2012" as date in the date-picker. But when I click the date-picker again, the UI calendar still shows the current(today) month and year and not the date previously selected.

You can see the full code here http://jsfiddle.net/kGzXR/1/

Can you please let me know if I am missing something here.

4

2 回答 2

2

如果您只需要月份和年份(因为这就是您在输入中存储的内容),您可以使用它:

$(function() { 
//set datepicker or month/year selection
        $('#a').datepicker( {
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy'
        }); 

        $("#a").focus(function () {
            $(".ui-datepicker-calendar").hide();
            //add event to perform on done button click
            $(".ui-datepicker-close").click(function(){
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $("#a").datepicker('option', 'defaultDate', new Date(year, month, 1));
            $("#a").datepicker('setDate', new Date(year, month, 1));
            });
        });   

});  

检查演示

于 2013-06-14T03:31:28.657 回答
0

如果日期突出显示是您的问题,那么您可以使用以下方法将其删除css

.ui-datepicker-today a.ui-state-highlight {
    border-color: #d3d3d3;
    background: #e6e6e6 url(/themeroller/images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;;
    color: #555555;    
}

JSF中。

于 2013-06-14T04:39:21.083 回答