jQuery ui datepicker - 仅显示日期范围内存在的月份

时间:2016-02-03 16:10:39

标签: jquery datepicker

我在多个日历中显示了一系列日期! 我想只显示我所拥有的日期范围内存在的月份日历! 无论如何我能做到这一点!或者至少从第一个现月而不是当月开始?

我的代码:

$.getJSON($controller + 'method' ,{param:param}, function(data){
            var dates = data.dates;
            var startDate = data.startDate;
            var numberOfMonths = data.numberOfMonths;

            $element.datepicker({
                beforeShowDay: function (date) {
                    var string = $.datepicker.formatDate('yy-mm-dd', date);
                    if (times.indexOf(string) != -1){
                        return [true, 'highlighted', 'date'];
                    }
                    else{
                        return [true, '', ''];
                    }
                },
                showCurrentAtPos:1,
                current: new Date(startDate),
                showWeek: true,
                format: 'Y-m-d',
                numberOfMonths: numberOfMonths,
                minDate:-1,
                maxDate:-2
            }).attr('readonly','readonly');
        })

1 个答案:

答案 0 :(得分:0)

var startDate = new Date(); //Your start date goes here
var endDate = new Date(); //Your end date goes here

$element.datepicker({
beforeShowDay: function(date) {
        var string = $.datepicker.formatDate('yy-mm-dd', date);
        if (times.indexOf(string) != -1) {
            return [true, 'highlighted', 'date'];
        } else {
            return [true, '', ''];
        }
    },
    showCurrentAtPos: 1,
    current: new Date(startDate),
    showWeek: true,
    format: 'Y-m-d',
    numberOfMonths: numberOfMonths,
    minDate: startDate,
    maxDate: endDate
    }).attr('readonly', 'readonly');
})

希望这有帮助