![](/img/trans.png)
[英]how to set the time range using javascript for the date of input html
[英]How to set range with Javascript for HTML input date
我需要为2个输入日期设置日期范围。 我知道我可以为此设置min
和max
,但这会迫使我选择特定的时间范围。 我要实现的是在第一个输入中选择任何日期,而在第二个输入中仅选择14天范围内的一天。
因此,例如,我希望能挑到14.01.2014
- 28.01.2014
,以及01.05.1992
- 15.05.1992
。 因此,我不能只使用
<input type="date" />
<input type="date" max="{{ctrl.maxDate"}}/>
有人知道如何动态设置最大值还是他们的range属性?
您可以将maxDate
设置为计算值。
var myApp = angular.module('myApp', []); myApp.controller('MyController', ['$scope', function($scope) { //Data $scope.startDate = new Date(); $scope.range = 14; //Functions $scope.maxDate = function () { var d = new Date($scope.startDate); d.setDate($scope.startDate.getDate() + $scope.range); return d; }; }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <div ng-app="myApp" ng-controller="MyController"> <input type="date" ng-model="startDate" /> <input type="date" min="{{ startDate | date:'yyyy-MM-dd' }}" max="{{ maxDate() | date:'yyyy-MM-dd' }}" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.