1、html代码如下所示:
复制代码
1
2
3
4
5
6<div> <button ng-repeat="t in deptName" class="deptDiv" ng-class="{'deptDivOnclick':selected==t.name}" ng-click="showDeptEmps(t.name )">{{ t.name }} </button> </div>
2、angular代码如下所示:
复制代码
1
2
3$scope.showDeptEmps = function (dName) { $scope.selected = dName; //设置点击按钮背景颜色 };
其中:
复制代码
1$scope.deptName = [{name;"部门1"},{name;"部门2"},{name;"部门3"},{name;"部门4"}];
3、CSS代码如下所示:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14.deptDiv { margin: 10px; width: 30%; font-size: 27px; background-color: #A1CF6D; color: white; padding-top: 10px; padding-bottom: 10px; padding-left: 20px; padding-right: 20px; } .deptDivOnclick { background-color: #008000; }
以上这篇angularJs使用ng-repeat遍历后选中某一个的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是勤劳手套最近收集整理的关于angularJs使用ng-repeat遍历后选中某一个的方法的全部内容,更多相关angularJs使用ng-repeat遍历后选中某一个内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复