多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选
生活随笔
收集整理的這篇文章主要介紹了
多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ng-checked:Angular里ng-checked屬性影響復(fù)選框的狀態(tài),值=>true則復(fù)選框選中,值=>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>序號(hào)</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部分:
//復(fù)選框事件$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);}});}//清空數(shù)組......//全選按鈕是否選中......}//全選$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; //全部設(shè)置成全選});$scope.viewModel.measureTableDivisorTopicInfos.splice(0, $scope.viewModel.measureTableDivisorTopicInfos.length);for (var i = 0; i < list.length; i++) {//......業(yè)務(wù)Code}} else {$scope.isAllSelect = false;angular.forEach($scope.vm.viewModel.measureTableTopicInfos, function (value, key) {value.isChecked = false; //全部設(shè)置成不選});}}簡(jiǎn)單粗暴的實(shí)現(xiàn)!
總結(jié)
以上是生活随笔為你收集整理的多选框实现全选_Angular1.x-checkbox-全选amp;单选amp;多选的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 二叉树的建立与遍历完整代码_腾讯面试官这
- 下一篇: 总线制和多线制示意图_主机总线线 总线制