【发布时间】:2019-09-21 15:34:28
【问题描述】:
我有两个输入字段,它们是日期选择器“startDate”和“endDate”。对于 startDate,最大日期应该是 endDate。对于 endDate,最小日期应该是 startDate。当我清除 startDate 并尝试为 endDate 设置新日期时,它给出“无效日期错误”,因为 min-Date(StartDate) 值已清除。请帮我解决这个问题
<div class="col l2 m4 s12 input-field">
<input id="startDate" type="text" ng-model="startDate" date-picker="date" format="D/M/YYYY" max-date="endDate" />
<label material-active="startDate" for="startDate">Min. Created Date</label>
<a class="clear-button" href="#" ng-click="clearDate($event, 'startDate')" ng-show="startDate">X</a>
</div>
<div class="col l2 m4 s12 input-field">
<input id="endDate" type="text" ng-model="endDate" date-picker="date" format="D/M/YYYY" min-date="startDate" />
<label material-active="endDate" for="endDate">Max. Created Date</label>
<a class="clear-button" href="#" ng-click="clearDate($event, 'endDate')" ng-show="endDate">X</a>
</div>
scope.clearDate = function (e, prop) {
e.preventDefault();
scope[prop] = '';
}
【问题讨论】:
-
您可以为字段添加 onChange 侦听器并使用几行 javascript 进行验证,以便您可以检查空值。
标签: javascript c# html