gpt4 book ai didi

javascript - 如何向 Bootstrap 折叠面板添加减号/加号图标

转载 作者:行者123 更新时间:2023-12-01 05:36:22 25 4
gpt4 key购买 nike

所以我正在使用 Bootstrap 并有折叠面板,我希望实现加号和减号图标。

我目前已经使用 stackoverflow 上找到的以下代码完成了此操作,我不记得链接了,因此稍后会进行编辑。它使用下面的代码,但是我必须为每组折叠面板复制它,因为它们具有唯一的 ID。有没有办法只需要一次,并且可以在同一页面上多次使用?

jQuery(function ($) {
var $active = $('#accordionthree .panel-collapse.in').prev().addClass('active');
$active.find('.symbol').append('<span class="glyphicon glyphicon-minus pull-left"></span>');
$('#accordionthree .panel-heading').not($active).find('.symbol').prepend('<span class="glyphicon glyphicon-plus pull-left"></span>');
$('#accordionthree').on('show.bs.collapse', function (e)
{
$('#accordionthree .panel-heading.active').removeClass('active').find('.glyphicon').toggleClass('glyphicon-plus glyphicon-minus');
$(e.target).prev().addClass('active').find('.glyphicon').toggleClass('glyphicon-plus glyphicon-minus');
});
$('#accordionthree').on('hide.bs.collapse', function (e)
{
$(e.target).prev().removeClass('active').find('.glyphicon').removeClass('glyphicon-minus').addClass('glyphicon-plus');
});
});

最佳答案

CSS解决方案:

.panel-heading a:after {
font-family:'Glyphicons Halflings';
content:"\2212";
float: right;
color: grey;
}
.panel-heading a.collapsed:after {
content:"\2b";
}

基于Collapse accordion example中的折叠示例 并使用 font-awesome .

希望这有帮助。

<小时/>

.panel-heading a:after {
font-family:'Glyphicons Halflings';
content:"\2212";
float: right;
color: grey;
}
.panel-heading a.collapsed:after {
content:"\2b";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="panel-group" id="accordion">
<div class="panel panel-default" id="panel1">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseOne"
href="#collapseOne">
Collapsible Group Item #1
</a>
</h4>

</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
</div>
</div>
<div class="panel panel-default" id="panel2">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseTwo"
href="#collapseTwo" class="collapsed">
Collapsible Group Item #2
</a>
</h4>

</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
</div>
</div>
<div class="panel panel-default" id="panel3">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseThree"
href="#collapseThree" class="collapsed">
Collapsible Group Item #3
</a>
</h4>

</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
</div>
</div>
</div>

关于javascript - 如何向 Bootstrap 折叠面板添加减号/加号图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33768294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com