帮助,我希望在 bootstrap 3 中折叠时交换 glyphicon 图像。我在这里找到了这个线程Bootstrap 3 Collapse show state with Chevron icon 这在 jsfiddle 中有效,但是当复制到我自己的页面时,折叠有效,但图标不交换从上到下。有什么我想念的吗?我什至把它放在了 Bootstrap 3 的完整下载版本中,但图标无法换出。这是代码:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
Collapsible Group Item #1
</a><i class="indicator glyphicon glyphicon-chevron-down pull-right"></i>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high...
</div>
</div>
</div>
</div>
</div>
这是js:
$('#accordion .accordion-toggle').click(function (e){
var chevState = $(e.target).siblings("i.indicator").toggleClass('glyphicon-chevron-down glyphicon-chevron-up');
$("i.indicator").not(chevState).removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
});