![](/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.