多级折叠侧边栏箭头方向改变

时间:2016-01-04 05:26:36

标签: javascript jquery twitter-bootstrap

我正在制作一个多级崩溃侧面菜单我使用bootstrap和jquery来实现它。但问题是当我点击链接时所有箭头同时改变方向 html是

<li>
     <div class="col-sm-12" style="background: #1f3d74;color: #ccc;"><span>MAIN NAVIGATION MENU</span></div>
</li>
<li> <a href="#1" ><span class="fa fa-dashboard"></span>  Dashboard</a></li>
<li><a href="#1" data-toggle="collapse" > <span class=""><span class="fa fa-wrench"></span> UI Elements</span> <i class="fa fa-angle-left pull-right"></i> </a>
    <ul class="sidebar-nav-second-level collapse" id="1">
         <li> <a href="javascript:void(0)">Menu 1</a> </li>
         <li> <a href="javascript:void(0)">Menu 2</a> </li>
         <li class="third-level"> 
             <a href="#12" data-toggle="collapse" > <span class="">Charts & Tables</span> <i class="fa fa-angle-left pull-right"></i> </a>
                 <ul class="sidebar-nav-third-level collapse" id="12">
                     <li> <a href="javascript:void(0)">Menu 1</a> </li>
                     <li> <a href="javascript:void(0)">Menu 2</a> </li>
                     <li> <a href="javascript:void(0)">Menu 3</a> </li>
                 </ul>
         </li>
    </ul>
</li>    

javascript代码

$(".sidebar-nav>li>a").click(function (e) {
    console.log(this, e.target, e.currentTarget);
    if ($(this).is(e.target)) {
        $('.sidebar-nav>li>a>i').toggleClass('fa-angle-left fa-angle-down', 200);
    }
});
$(".sidebar-nav>li>ul>li>a").on('click', function (e) {
   if ($(this).is(e.target)) {
       $('.sidebar-nav>li>ul>li>a>i').toggleClass('fa-angle-left fa-angle-down', 200);
   }
});

当我点击Dashboard链接时,ui元素的箭头正在改变方向 请帮忙。 感谢

1 个答案:

答案 0 :(得分:1)

我认为您可能需要&#39;每个&#39;,就像这样:

$(".sidebar-nav>li>a").each(function(){
    $(".sidebar-nav>li>a").click(function (e) {
        if ($(this).is(e.target)) {
           $('.sidebar-nav>li>a>i').toggleClass('fa-angle-left fa-angle-down', 200);
  }
  });
});

其他代码相同;