angularjs显示/隐藏选项卡,单击相同选项卡隐藏内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs显示/隐藏选项卡,单击相同选项卡隐藏内容相关的知识,希望对你有一定的参考价值。
当我点击标签A,一个内容显示
当我点击标签B时,A内容隐藏B内容显示
但我想要的效果是当我点击标签A,内容显示,再次单击一个标签内容隐藏。
任何建议将有助于谢谢
<ul class="row text-center">
<li class="col col-33">
<a href="javascript:void(0);" ng-class="{selected: tab==a}" ng-click="tab = a ">a <i class="icon ion-arrow-down-b"></i></a>
</li>
<li class="col col-33">
<a href="javascript:void(0); " ng-class="{selected: tab==b}" ng-click="tab = b ">b <i class="icon ion-arrow-down-b"></i></a>
</li>
<li class="col col-33">
<a href="javascript:void(0);" ng-class="{selected: tab==c}" ng-click="tab = c ">c <i class="icon ion-arrow-down-b"></i></a>
</li>
</ul>
<div class="a" ng-show="tab == a">a</div>
<div class="b" ng-show="tab == b">b</div>
<div class="c" ng-show="tab == c">c</div>
答案
您需要将ng-click
的表达式更改为ng-click="tab = tab=='a'? null: 'a'"
<ul class="row text-center">
<li class="col col-33">
<a href="javascript:void(0);" ng-class="{selected: tab=='a'}" ng-click="tab = tab=='a'? null: 'a'">
a <i class="icon ion-arrow-down-b"></i>
</a>
</li>
<li class="col col-33">
<a href="javascript:void(0); " ng-class="{selected: tab=='b'}" ng-click="tab = tab=='b'? null: 'b' ">
b
<i class="icon ion-arrow-down-b"></i></a>
</li>
<li class="col col-33">
<a href="javascript:void(0);" ng-class="{selected: tab=='c'}" ng-click="tab = tab=='c'? null: 'c' ">
c <i class="icon ion-arrow-down-b"></i>
</a>
</li>
</ul>
<div class="a" ng-show="tab == 'a'">a</div>
<div class="b" ng-show="tab == 'b'">b</div>
<div class="c" ng-show="tab == 'c'">c</div>
另一答案
我已回答像这样的Implementing angularJs factory or service for bootstrap tabs
和我准备好的例子here一样
<ul>
<li ng-class="{active:tab===1}">
<a href ng-click="tab = tab==1 ? a : 1">Tab1</a>
</li>
<li ng-class="{active:tab===2}">
<a href ng-click="tab = tab==2 ? a : 2">Tab2</a>
</li>
<li ng-class="{active:tab===3}">
<a href ng-click="tab = tab==3 ? a : 3">Tab3</a>
</li>
<br><br>
<p ng-show="tab === 1"> Tab1 content </p>
<p ng-show="tab === 2"> Tab2 content</p>
<p ng-show="tab === 3"> Tab3 content</p>
</ul>
在这里,qazxsw poi只不过是qazxsw poi
另一答案
宁愿将ng-click块null修改为tab,因为单击同一个选项卡时不会发生任何事情!
a
以上是关于angularjs显示/隐藏选项卡,单击相同选项卡隐藏内容的主要内容,如果未能解决你的问题,请参考以下文章