简体   繁体   中英

Jquery ui date picker inst.inline:false

I'm using jQuery ui Datepicker to display events.

$( "#datepicker2" ).datepicker({
    dateFormat: 'dd MM',
    showWeek: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    defaultDate: "+1M",
    onSelect: function (param, param2) {
        param2.inline = false;
        var datecurrent=$("#datepicker2").datepicker('getDate');
    },
    beforeShowDay: function(date) {
            for (i = 0; i < holiDays.length; i++) {
                if (date.getFullYear() == holiDays[i][0]
                        && date.getMonth() == holiDays[i][1] - 1
                        && date.getDate() == holiDays[i][2]) {
                        return [true, holiDays[i][4], holiDays[i][3]];
                    }
                }
            return [true, ''];
        }
    });

To prevent the redrawing the calender on select, i specified param2.inline = false.But the issue is when i clicked on 13-jan-2015, i'm getting result as 13-jan 2014.

You need to include the year in the dateFormat . When getting the date, the datepicker parses the contents of the input field. Since there's no year there, it defaults to the current year.

$("#datepicker2").datepicker({
    dateFormat: 'dd MM yy',
    showWeek: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    defaultDate: "+1M",
    onSelect: function (param, param2) {
        var datecurrent = $("#datepicker2").datepicker('getDate');
    },
    beforeShowDay: function (date) {
        for (i = 0; i < holiDays.length; i++) {
            if (date.getFullYear() == holiDays[i][0] && date.getMonth() == holiDays[i][1] - 1 && date.getDate() == holiDays[i][2]) {
                return [true, holiDays[i][4], holiDays[i][3]];
            }
        }
        return [true, ''];
    }
});

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM