开发者

jQuery UI Datepicker - default day of month on month change

开发者 https://www.devze.com 2023-03-31 08:17 出处:网络
I need a specific behavior of jQuery UI Datepicker: By clicking on \'Prev/Next Month\' current day of month must be automatically set in the previous/next month.

I need a specific behavior of jQuery UI Datepicker:

By clicking on 'Prev/Next Month' current day of month must be automatically set in the previous/next month.

e.g.: default date was set to 8/25/2011, after clicking 'Next month' (or selecting September in dropdown), 9/25/2开发者_高级运维011 must be automatically selected (but not populated to input and datepicker itself must not disappear, so user can change this default day of month).

Thanks for advice.


You can make use of the beforeShowDay event.

var defaultDay = 15;
$('#datepicker').datepicker({
    beforeShowDay: function(date) {
        if (date.getDate() == defaultDay)
            return [1, 'ui-state-highlight ui-state-active'];  // can replace with a customised class
        return [1, ''];
    },
    defaultDate: '07/' + defaultDay + '/2011'
});

You can assign a customised class yourself and style it to your heart's content.

Example: http://jsfiddle.net/william/nNmg2/

Note: you may need to take care of double-digit padding, if defaultDay is 1 to 9.

0

精彩评论

暂无评论...
验证码 换一张
取 消