jQuery datepicker在本月末显示在下个月 [英] jQuery datepicker show next month if near the end of current month

查看:138
本文介绍了jQuery datepicker在本月末显示在下个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果当前日期临近月底,如何设置日历以自动显示下个月?

If the current date is near the end of the month, how can I set the calendar to auto show the next month?

要解决日历默认使用的问题.

To solve the issue of the calendar ever defaulting to this.

目前,我有:

$(predecessor+"input.datePicker").datepicker({
    minDate: 0,
    changeMonth: true,
    dateFormat: "dd/mm/yy",
    firstDay: 1,
    hideIfNoPrevNext: true,
    showAnim: 'slideDown',
    showOn: "both",  
    showOtherMonths: true,
    showStatus: true,
    maxDate: '-1d'
});

推荐答案

使用beforeShow事件设置属性numberOfMonths

$('#calendar').datepicker({
    //minDate: 0,
    changeMonth: true,
    dateFormat: "dd/mm/yy",
    firstDay: 1,
    hideIfNoPrevNext: true,
    showAnim: 'slideDown',
    showOn: "both",  
    showOtherMonths: true,
    showStatus: true,
    //maxDate: '-1d'
    beforeShow: function(text, inst){        
        var next_day = new Date(
            inst.selectedYear,
            inst.selectedMonth,
            inst.selectedDay
        );        
        next_day.setDate(next_day.getDate()+1);
        console.log(inst.selectedMonth);
        console.log(next_day.getMonth());
        if(inst.selectedMonth != next_day.getMonth())
            return {numberOfMonths: 2};
        else
            return {numberOfMonths: 1};
    }
}).datepicker("setDate", "+0d" );​

演示: http://jsfiddle.net/Z44PQ/1/,选择11月30日,然后再次打开.

Demo : http://jsfiddle.net/Z44PQ/1/, select 30 Nov and open again.

这篇关于jQuery datepicker在本月末显示在下个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆