禁用Month/DatePicker上的月份

mur*_*983 6 javascript jquery jquery-ui-datepicker bootstrap-datepicker

请看我的小提琴.

我有一个月度选择器,只允许用户提前一年选择,但我想要的是过去几个月被禁用,以及提前一年被禁用的任何月份,但我无法弄清楚如何让这个工作.

示例场景当前月份为"十月",因此"2015年"月份"1月至9月"将被禁用,"11月至12月"月份将被禁用为"2016年"

我尝试过使用minDate:"0"和maxDate:"1y"但它们不起作用.

HTML

<div class="input-group date" style="width: 200px">
    <input type="text" id="example1" class="form-control" style="cursor: pointer"/>
        <span class="input-group-addon">
            <i class="glyphicon glyphicon-calendar"></i>
        </span>
</div>
Run Code Online (Sandbox Code Playgroud)

JQuery的

$('#example1').datepicker
({
    format: "MM yyyy",
    minViewMode: 1,
    autoclose: true,
    startDate: new Date(new Date().getFullYear(), '0', '01'),
    endDate: new Date(new Date().getFullYear()+1, '11', '31')
});
Run Code Online (Sandbox Code Playgroud)

Gur*_*Rao 7

DEMO

您可以使用startDate,endDate但尝试在外部的某处分配日期变量,如下所示:

var date=new Date();
var year=date.getFullYear(); //get year
var month=date.getMonth(); //get month

$('#example1').datepicker
({
    format: "MM yyyy",
    minViewMode: 1,
    autoclose: true,
    startDate: new Date(year, month, '01'), //set it here
    endDate: new Date(year+1, month, '31')
});
Run Code Online (Sandbox Code Playgroud)