year/month only datepicker inline

2019-08-02 05:01发布

I need to create a jquery ui datepiker that only shows year and month:

$(document).ready(function () {
    var montPiker = $(".monthPicker").datepicker({
        changeMonth: true,
        changeYear: true,
    });

    $(".monthPicker .ui-datepicker-calendar").hide();
});

 <div id="monthPicker" class="monthPicker"></div>

the idea is to have a month/year inline picker, but the problem I'm having is that after I change the month or year the callendar part is shown again. I have try to reapply the .hide() but I can't find on which event should it happend.

Anyone know, how to solve this? thanks.

1条回答
时光不老,我们不散
2楼-- · 2019-08-02 05:25

The actual problem is after initializing the datepicker, you're hiding the calender. Hence the calender is showing up, whenever you change the year/month.

The best way is to do with CSS, an explicit approach.

.monthPicker .ui-datepicker-calendar {
display: none;
}

JSFiddle

Hope this helps.

查看更多
登录 后发表回答