时间:2021-02-19 15:17:18 | 栏目:AngularJS | 点击:次
页面代码:
<!-- 弹出层 --> <section class="popup-bg" ng-if="IsActive"> <div class="popup-box phone-detail"> <div class="popup-title popup-detail-title">通讯录 <i class="iconfont popup-close-font rights " ng-click="HideMail()"></i> </div> <div class="content"> <div class="phone" ng-repeat="User in NoticeUserList">{{User.Name}} <div class="check-item rights"> <div class="check-bg" ng-class="{true:'checkeds',false:'uncheckeds',}[active]"> </div> <input type="checkbox" ng-model="active" class="checkboxs" value="User.Name" ng-click="itemSelected($event,User.Id,active)"> </div> </div> </div> </div> </section>
Controller中代码:
$scope.itemIds = []; $scope.active = false; $scope.itemSelected = function ($event, pid, active) { var checkbox = $event.target; if (checkbox.checked) { $scope.itemIds.push(pid); } else { $scope.itemIds = Tools.arrRemove($scope.itemIds, pid); } console.log(active); console.log($scope.itemIds); };
总结: 此处开始写的时候没有使用NG-MODEL,导致复选框选中一个,其他的复选框样式都跟着变化了,重点就是加上NG-MODEL,并且和NG-CLASS设置的[]中的名称一致即可。