Angularjs 禁用提交按钮,直到选中2或3个复选框,使用
我想使用Angular禁用Submit按钮,直到选中2或3个复选框 请参阅下面的启动代码示例。我不确定角度是否是最好的方式Angularjs 禁用提交按钮,直到选中2或3个复选框,使用,angularjs,Angularjs,我想使用Angular禁用Submit按钮,直到选中2或3个复选框 请参阅下面的启动代码示例。我不确定角度是否是最好的方式 我需要支持IE8和更旧的浏览器 有小费吗 <!DOCTYPE html> <html ng-app="todoApp"> <head> <script type="text/javascript" src="angular.min.js"></script> <script> var model
我需要支持IE8和更旧的浏览器 有小费吗
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<script type="text/javascript" src="angular.min.js"></script>
<script>
var model = {
user: "Adam",
items: [{ action: "Flowers", done: false },
{ action: "Shoes", done: false },
{ action: "Tickets", done: false },
{ action: "Cimputer", done: false }]
};
var todoApp = angular.module("todoApp", []);
todoApp.controller("ToDoCtrl", function ($scope) {
$scope.todo = model;
});
</script>
</head>
<body ng-controller="ToDoCtrl">
<table>
<tr ng-repeat="item in todo.items">
<td>{{item.action}}</td>
<td><input type="checkbox" ng-model="item.done" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save"/></td>
</tr>
</table>
</body>
</html>
var模型={
用户:“亚当”,
项目:[{行动:“鲜花”,完成:错误},
{动作:“鞋子”,完成:错误},
{动作:“罚单”,完成:false},
{操作:“计算机”,完成:错误}]
};
var todoApp=angular.module(“todoApp”,[]);
todoApp.controller(“ToDoCtrl”,函数($scope){
$scope.todo=模型;
});
{{item.action}
如果您不需要支持IE8或更早版本的浏览器,可以使用AngularJSngDisabled
指令
ngDisabled
允许您基于$scope
变量的布尔值禁用按钮。以下是当$scope.isDisabled
为true时禁用的按钮示例
<button ng-disabled="{{scope.isDisabled}}">Save</button>
保存
然后,只要选中/取消选中复选框,您就可以使用类似于$scope.$watchCollection
的内容来更新$scope.isDisabled
您可以从AngularJS文档中找到更多关于ngDisabled的信息:如果您不需要支持IE8或更早版本的浏览器,可以使用AngularJS
ngDisabled
指令
ngDisabled
允许您基于$scope
变量的布尔值禁用按钮。以下是当$scope.isDisabled
为true时禁用的按钮示例
<button ng-disabled="{{scope.isDisabled}}">Save</button>
保存
然后,只要选中/取消选中复选框,您就可以使用类似于$scope.$watchCollection
的内容来更新$scope.isDisabled
您可以从AngularJS文档中找到更多关于ngDisabled的信息:您可以通过“完成”筛选项目,并检查筛选的列表长度是否足够长
<td><input type="submit" value="Save" ng-disabled="(todo.items | filter: item.done != true).length < 2" /></td>
如果您还想限制最大值,可以执行以下操作
<td><input type="submit" value="Save" ng-disabled="((todo.items | filter: item.done != true).length < 2) || ((todo.items | filter: item.done != true).length > 3)" /></td>
您可以通过“完成”筛选项目,并检查筛选的列表长度是否足够长
<td><input type="submit" value="Save" ng-disabled="(todo.items | filter: item.done != true).length < 2" /></td>
如果您还想限制最大值,可以执行以下操作
<td><input type="submit" value="Save" ng-disabled="((todo.items | filter: item.done != true).length < 2) || ((todo.items | filter: item.done != true).length > 3)" /></td>
我需要对IE8及以上版本的支持browsers@user3635120-好的,那很好,但在问题中可能值得详细说明。当我的回答像你最初写的那样回答问题时,我不喜欢投反对票。无论如何,不要接受它,尽管要求一个替代的解决方案。我需要IE8和更旧版本的支持browsers@user3635120-好的,那很好,但在问题中可能值得详细说明。当我的回答像你最初写的那样回答问题时,我不喜欢投反对票。无论如何,不要接受它,尽管要求另一种解决方案。效果很好!如果我想选中mininum 2和max 3复选框,这是一个改进,我该怎么做?非常好!如果我想选中mininum 2和max 3复选框,这是一个改进,我该怎么做?