当我们点击ul中的列表项下拉列表时,我必须将fa-angle-left更改为fa-angle-down。请参考以下代码。
<nav>
<ul class="nav nav-pills nav-stacked panel-group " id="accordion" data-spy="affix" data-offset-top="605">
<!--<li class="active"><a href="#section1">Section 1</a></li>
<li><a href="#section2">Section 2</a></li>
<li><a href="#section3">Section 3</a></li>-->
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo1" data-parent="#accordion" style="margin-left: 0px; margin-top:"> <i class="fa fa-calendar " style="margin-right: 10px;"></i>Planning<i class="fa fa-angle-left " style="float: right !important;"></i> </a>
<ul id="demo1" class="collapse ">
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
YE
</span><a ui-sref="">Yearly</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
MO
</span><a ui-sref="">Monthly</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo2" data-parent="#accordion" style="margin-left: 0px; margin-top:"> <i class="fa fa-book " style="margin-right: 10px;"></i>Order<i class="fa fa-angle-left" style="float: right !important;"></i> </a>
<ul id="demo2" class="collapse " data-parent="#accordion">
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px; text-decoration: none ;">
AL
</span><a ui-sref="dashboard">All</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
SE
</span><a ui-sref="sector">Sector</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
DR
</span><a ui-sref="">Date Range</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
DE
</span> <a ui-sref="">Delivered</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
PE
</span><a ui-sref="">Pending</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo3" data-parent="#accordion" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck" style="margin-right: 10px;"></i>Logistics<i class="fa fa-angle-left" style="float: right !important;"></i> </a>
<ul id="demo3" class="collapse" data-parent="#accordion">
<li style="margin-left: 0px"> <span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
AL
</span><a ui-sref="">All</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
SE
</span><a ui-sref="">Sector</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
CU
</span><a ui-sref="">Customer</a></li><br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
PE
</span><a ui-sref="">Pending</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo4" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck" style="margin-right: 10px;"></i>Delivery </a>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo4" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck" style="margin-right: 10px;"></i>Delivery </a>
</li>
</ul>
</nav>
建议我为实现这一目标必须做出哪些改变。 请参考JsFiddle https://jsfiddle.net/ArunKumarUmma/4oyLhsup/1/
答案 0 :(得分:3)
我们可以使用Jquery本身尝试以下代码来实现这一点。
<i class="fa fa-angle-left" onClick="($(this)[0].className == 'fa fa-angle-left')?$(this)[0].className='fa fa-angle-down':$(this)[0].className='fa fa-angle-left'" style="float: right !important;"></i>
答案 1 :(得分:3)
我使用了以下jQuery:
$('a').on('click', function(e) { $(this).find('[class*="angle"]').toggleClass('fa-angle-left fa-angle-down') });
这意味着:单击任何<a>
nchor,找到包含字符串angle
的className的任何元素。如果找到toggleClass()
两个类.fa-angle-left
和.fa-angle-down
。
我添加了CSS而不是内联样式。我还添加了奖励,点击最后2个卡车图标。
<强>段强>
$('a').on('click', function(e) {
$(this).find('[class*="angle"]').toggleClass('fa-angle-left fa-angle-down')
});
$('.go').on('click', function(e) {
$(this).css({
transform: 'translateX(-195px)',
transition: 'transform .5s'
});
});
&#13;
.panel>a {
display: table-row;
}
i {
display: table-cell
}
i:last-of-type {
float: right
}
&#13;
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/fontawesome/4.6.3/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
<nav>
<ul class="nav nav-pills nav-stacked panel-group " id="accordion" data-spy="affix" data-offset-top="605">
<!--<li class="active"><a href="#section1">Section 1</a></li>
<li><a href="#section2">Section 2</a></li>
<li><a href="#section3">Section 3</a></li>-->
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo1" data-parent="#accordion" style="margin-left: 0px; margin-top:">
<i class="fa fa-calendar" style="margin-right:10px;"></i> Planning
<i class="fa fa-angle-left"></i>
<!-- ✎ -->
</a>
<ul id="demo1" class="collapse">
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
YE
</span><a ui-sref="">Yearly</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
MO
</span><a ui-sref="">Monthly</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo2" data-parent="#accordion" style="margin-left: 0px; margin-top:"> <i class="fa fa-book " style="margin-right: 10px;"></i>Order
<i class="fa fa-angle-left"></i>
<!-- ✎ -->
</a>
<ul id="demo2" class="collapse " data-parent="#accordion">
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px; text-decoration: none ;">
AL
</span><a ui-sref="dashboard">All</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
SE
</span><a ui-sref="sector">Sector</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
DR
</span><a ui-sref="">Date Range</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
DE
</span>
<a ui-sref="">Delivered</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
PE
</span><a ui-sref="">Pending</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo3" data-parent="#accordion" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck" style="margin-right: 10px;"></i>Logistics<i class="fa fa-angle-left"></i>
</a>
<ul id="demo3" class="collapse" data-parent="#accordion">
<li style="margin-left: 0px"> <span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
AL
</span><a ui-sref="">All</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
SE
</span><a ui-sref="">Sector</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
CU
</span><a ui-sref="">Customer</a></li>
<br>
<li style="margin-left: 0px"><span class="thumbnail" style="display:inline;border: 0px solid;background-color:#21252d;color:white;font-size:9px;margin-right: 12px;">
PE
</span><a ui-sref="">Pending</a></li>
</ul>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo4" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck go" style="margin-right: 10px;"></i>Delivery
</a>
</li>
<li class="panel" style="margin-top: 0px">
<a href="javascript:;" data-toggle="collapse" data-target="#demo4" style="margin-left: 0px; margin-top:"> <i class="fa fa-truck go" style="margin-right: 10px;"></i>Delivery
</a>
</li>
</ul>
</nav>
&#13;
答案 2 :(得分:1)
:
$scope.someVar = true;
模板中的:
<li ng-click="someVar = !someVar"></li>
<i ng-class="{'fa-angle-left': someVar, 'fa-angle-down': !someVar}"></i>
</li>
点击li
后,它会在范围内切换变量someVar
,并根据i
是真还是假<导致类在someVar
上更改< / p>