2014-09-25 68 views
0

有两个字段。我需要一个比第二个更小,第二个比第一个更多,同时通过验证。具有最小/最大参数的验证号码

但是,在进入第一个号码时不保存在模型(保存为未定义),因为没有通过验证条件“最大”

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

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

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

回答

0

它比我想象

我只是删除测试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

0

您是否尝试初始化控制器中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>

+0

是的,我设置在低0和高1. 在你的例子有这个问题。 重要的是键盘输入,而不是按钮 – zam 2014-09-25 16:55:24

相关问题