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');
}
});