辛苦各位了,请问如何用一组按钮来做单选的问题,万分感谢!
1、页面加载后,根据传回的值
domain:"8"
,设置默认勾选的按钮和按钮里的图标class;
2、点击一个按钮,清除其他按钮样式,并给点击的按钮添加 classactive
效果图如下(现在是直接用添加class形成的)
{
1: "健康",
2: "法律",
3: "心理",
4: "医美",
5: "教育",
6: "职场",
7: "汽修",
8: "其他"}
<ul class="tag-list button-select-group">
<li ng-repeat="item in domainList">
<button type="button"
ng-class="{active:$index + 1 == defaultDomain}"
ng-click="checkDomain($index+1)"
ng-model="domain"
class="btn-item btn-domain aui-btn aui-btn-secondery aui-btn-block"
value="{{$index+1}}">
{{item}}
<span ng-class="{'fa fa-check-square':$index + 1 == defaultDomain}"></span>
</button>
</li>
</ul>
$scope.defaultDomain = data.domain;//服务器返回的domain字段数据
$scope.checkDomain = function (id) {
$scope.defaultDomain=id;
}
習慣沉默2017-05-15 17:11:33
Define a variable and assign the current value to it, and then make a judgment in the class. If the value = index, add the style
过去多啦不再A梦2017-05-15 17:11:33
Use the radio format to do it directly, just hide the default style, and then make a fuss about the style of the corresponding label