Angularjs:如何在按钮上添加活动类

时间:2016-05-06 10:18:37

标签: html angularjs

我可以使用AngularJS在按钮上添加active类吗?

例如:

<button class="first">first</button>
<button class="second">second</button>
<button class="third active">third</button>
<button class="fourth">fourth</button>

默认情况下,我想在third上设置活动类,然后删除该类并将其添加到所选按钮。

1 个答案:

答案 0 :(得分:0)

试试这个

<button class="first" ng-class="{'active':selcted == 'first'}">first</button>
<button class="second" ng-class="{'active':selcted == 'second'}">second</button>
<button class="third" ng-class="{'active':selcted == 'third'}">third</button>
<button class="fourth" ng-class="{'active':selcted == 'fourth'}">fourth</button>

JS

$scope.selcted = 'third';