Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter bootstrap 3 当导航项目打开时更改glyphicon的类别_Twitter Bootstrap 3 - Fatal编程技术网

Twitter bootstrap 3 当导航项目打开时更改glyphicon的类别

Twitter bootstrap 3 当导航项目打开时更改glyphicon的类别,twitter-bootstrap-3,Twitter Bootstrap 3,我正在网页上使用引导菜单 我的菜单列表如下所示: <li><a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria- expanded="false">main item <span class="pull-

我正在网页上使用引导菜单

我的菜单列表如下所示:

       <li><a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" 
       role="button" data-toggle="dropdown" aria-haspopup="true" aria- 
       expanded="false">main item

        <span class="pull-left glyph-btn-menu">
       <em class="glyphicon glyphicon-menu-down"></em>
       </span>
       </a>

        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        sub item1<br>
        sub item2<br>
        sub item2<br>
        </div>
        </li>
  • 分项1
    分项2
    分项2
  • 我希望glyphicon符号在单击导航链接并打开子菜单项时更改为向上类glyphicon菜单,然后在导航项关闭或单击其他导航项时再次更改为向下类glyphicon菜单


    实现这一点的最佳方法是什么?这就是我的解决方案

    我给了父ul一个id值:id=“theme”

    bootstrap将打开的类添加到打开的li中,因此我检查是否有任何li打开了该类,根据需要删除并添加glyphicon类

            $('#theme li').click(function () {
              if($(this).hasClass('open')){
                  //alert('aaa');
                    $(this).children('a').children('span').children('em').removeClass('glyphicon-menu-up');
                  $(this).children('a').children('span').children('em').addClass('glyphicon-menu-down');
                  } else {
                    $(this).children('a').children('span').children('em').removeClass('glyphicon-menu-down');
                  $(this).children('a').children('span').children('em').addClass('glyphicon-menu-up');
                      }
            });