我正在使用带有Bootstrap Glyphicon组件的按钮,并且在一个页面上有很多按钮,它使用折叠来显示隐藏的部分。这是我有的示例代码
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button>
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button>
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#sixts-section-collapse">Prijava <span class="glyphicon glyphicon-menu-down"></span></button>
我需要的是当用户点击该按钮并显示折叠只是为了将该图标从向下更改为向上时,我知道我可以为所有人创建全局图标,但我需要只检查该按钮,并在该按钮上显示另一个图标。这意味着何时关闭图标,以及何时打开图标
答案 0 :(得分:3)
$(document).ready(function(){
$("button[data-toggle=collapse]").click(function(){
$(this).find('span:first').toggleClass('glyphicon-chevron-down glyphicon-chevron-up')
});
});
工作演示
$(".collapse").collapse()
$("button[data-toggle=collapse]").click(function(){
$(this).find('span:first').toggleClass('glyphicon-chevron-down glyphicon-chevron-up')
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">
<span class="glyphicon glyphicon-chevron-down"></span> Open
</button>
</h4>
</div>
<div id="demo" class="panel-collapse collapse in">
<div class="panel-body">
Contents:Thank you to help me solve the problem, you're a great guy!
</div>
</div>
</div>
</div>
</div>
&#13;
答案 1 :(得分:1)
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.common.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.rtl.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.silver.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.mobile.all.min.css"/>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.112/js/kendo.all.min.js"></script>
<div id="chart"></div>