如何在Datepicker Angular JS中设置最大日期? [英] How to set max date in Datepicker Angular JS?

查看:360
本文介绍了如何在Datepicker Angular JS中设置最大日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试像:



JS代码:

  var today = new Date(); 
var dd = today.getDate();
var mm = today.getMonth()+ 6;
var yyyy = today.getFullYear();

$ scope.maxDate = yyyy +' - '+ mm +' - '+ dd;

HTML代码


$ b $ min-date =minDatemax-mode =maxDatedatepicker-options = dateOptionsclass =form-controldatepicker-popup ={{format}}ng-model =dtModel/>


解决方案

尝试这个,应该工作:

  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


I tried like as:

JS code:

 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"/>

解决方案

Try this, should work :

var today = new Date();

$scope.maxDate = new Date(today.getFullYear(), today.setMonth()+6, today.getDate());

EDIT Sorry, my bad :

var today = new Date();
  today.setMonth(today.getMonth()+6);


  $scope.maxDate = new Date(today.getFullYear(),today.getMonth() , today.getDate());

I tested it on plunker : http://plnkr.co/edit/Qb9N0OjhHWIH9ChtbF1J?p=preview

这篇关于如何在Datepicker Angular JS中设置最大日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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