我试着像:
JS代码:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+6;
var yyyy = today.getFullYear();
$scope.maxDate = yyyy + '-' + mm + '-' + dd;
HTML code:
<input type="text" ng-click="open($event)" min-date="minDate" max-mode="maxDate" datepicker-options="dateOptions" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel"/>
答案 0 :(得分:2)
试试这个,应该有效:
var today = new Date();
$scope.maxDate = new Date(today.getFullYear(), today.setMonth()+6, today.getDate());
修改强> 对不起,我的不好:
var today = new Date();
today.setMonth(today.getMonth()+6);
$scope.maxDate = new Date(today.getFullYear(),today.getMonth() , today.getDate());
我在plunker上测试了它:http://plnkr.co/edit/Qb9N0OjhHWIH9ChtbF1J?p=preview
答案 1 :(得分:0)
按照上述@ThomasWeglinski的建议将max-mode
更改为max-date
。
然后将你从现在计算的6个月改为:
var sixMonthsFromNow = today.setMonth(today.getMonth()+6);
var dd = sixMonthsFromNow.getDate();
var mm = sixMonthsFromNow.getMonth();
var yyyy = sixMonthsFromNow.getFullYear();
$scope.maxDate = yyyy + '-' + mm + '-' + dd;