angularjs show/hide tabs, click same tab hide the content

杀马特。学长 韩版系。学妹 提交于 2019-12-05 03:20:21

问题


when i click tab A, A content show

when i click tab B, A content hide B content show

but the effect i want is when i click tab A, A content show, click A tab again content hide.

Any suggest will be help thanks

<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>

回答1:


You need to change your expression of ng-click to 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>



回答2:


I have Answered like this Implementing angularJs factory or service for bootstrap tabs

same as I ready the example 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>

here a is noting but NULL




回答3:


In would rather modify the ng-click block null to tab, as on clicking on the same tab nothing should happen!

<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'? 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 = 
    tab=='b'? 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 = 
    tab=='c'? 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>


来源:https://stackoverflow.com/questions/30130391/angularjs-show-hide-tabs-click-same-tab-hide-the-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!