多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选
生活随笔
收集整理的這篇文章主要介紹了
多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ng-checked:Angular里ng-checked屬性影響復選框的狀態,值=>true則復選框選中,值=>false則取消選中。
HTML:
<div class="col-lg-4"><fieldset><legend>選題列表</legend><div class="table-responsive" style="border:0px;padding:3px;padding:0px;height:550px;overflow-y:scroll;"><table class="table table-bordered table-striped"><thead><tr><th><input type="checkbox" ng-checked="isAllSelect" ng-click="selectAll($event)" /></th><th>序號</th><th>題目</th></tr></thead><tbody><tr ng-repeat="x in viewModel.measureTableTopicInfos"><td><input type="checkbox" ng-model="x.isChecked" ng-click="onchecked(x,$event)" ng-checked="x.isChecked"></td><th scope="row">{{$index+1}}</th><td>{{x.title}}</td></tr></tbody></table></div></fieldset></div>Js部分:
//復選框事件$scope.onchecked = function (obj, evn) {var list = [];if (evn.target.checked) {angular.forEach($scope.viewModel.measureTableTopicInfos, function (value, key) {if (value.isChecked == true) {list.push(value.code);}});} else {angular.forEach($scope.viewModel.measureTableTopicInfos, function (value, key) {if (value.isChecked == true) {list.push(value.code);}});}//清空數組......//全選按鈕是否選中......}//全選$scope.selectAll = function ($event) {//如果全選了if ($event.target.checked) {var list = [];$scope.isAllSelect = true;angular.forEach($scope.viewModel.measureTableTopicInfos, function (value, key) {list.push(value.code);value.isChecked = true; //全部設置成全選});$scope.viewModel.measureTableDivisorTopicInfos.splice(0, $scope.viewModel.measureTableDivisorTopicInfos.length);for (var i = 0; i < list.length; i++) {//......業務Code}} else {$scope.isAllSelect = false;angular.forEach($scope.vm.viewModel.measureTableTopicInfos, function (value, key) {value.isChecked = false; //全部設置成不選});}}簡單粗暴的實現!
總結
以上是生活随笔為你收集整理的多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二叉树的建立与遍历完整代码_腾讯面试官这
- 下一篇: 总线制和多线制示意图_主机总线线 总线制