首页 > 代码库 > angular 复选框回选
angular 复选框回选
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="http://www.mamicode.com/js/angular.min.js"></script> </head> <body ng-controller="main"> <div ng-repeat="item in list"> <input type="checkbox" ng-checked="isSelect(item.id)" value="http://www.mamicode.com/item.id" ng-click="select(item.id,$event)"/>{{item.device}} </div> <div>{{result}}</div> <script> var app = angular.module(‘myApp‘,[]); app.controller(‘main‘,[‘$scope‘,function($scope) { $scope.list = [ {‘id‘:1,‘device‘:‘摄影‘}, {‘id‘:2,‘device‘:‘视屏‘}, {‘id‘:3,‘device‘:‘音乐‘} ] $scope.result = [1];//默认选中1 $scope.select = function(id,event) { console.log(event); var action = event.target; console.log(action); if(action.checked) { //选中添加 if($scope.result.indexOf(id) == -1) { $scope.result.push(id); } }else { //不选中删除 var selectId = $scope.result.indexOf(id); if(selectId !=-1) { $scope.result.splice(selectId,1); } } } $scope.isSelect = function(id) { return $scope.result.indexOf(id) != -1; } }]); </script> </body> </html>
angular 复选框回选
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。