具有最小/最大参数的验证编号

Validation number with min/max parameters

本文关键字:验证 参数 编号      更新时间:2023-09-26

有两个字段。我需要一个比第二个小,第二个比第一个多,同时通过验证。

然而,当输入第一个数字时,不会保存在模型中(保存为未定义),因为没有通过验证条件"最大"

对我来说重要的是键盘输入而不是按钮

有人能帮我解决这个问题吗?

<td><input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required></td>
<td><input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required></td>

您是否尝试在控制器中初始化item.low和item.high的值?

<!DOCTYPE html>
<html data-ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>
  <body ng-init="item.low=0;item.high=1;">
    <input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required>
    <input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required>
    <p>item.high={{item.high}}</p>
    <p>item.low={{item.low}}</p>
  </body>
</html>

这比我想象的更容易

我刚刚删除了第一个INPUT中对max的测试,他没有必要并且验证成功并且数据是正确的

<td><input type="number" class="form-control input-sm" ng-model="item.low" required></td>
<td><input type="number" class="form-control input-sm" ng-model="item.high"  min="{{item.low+1}}" required></td>

ty all for help