Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在引导中为手风琴添加加号或减号?关闭手风琴时显示加号,打开手风琴时显示减号_Javascript_Jquery_Html_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 如何在引导中为手风琴添加加号或减号?关闭手风琴时显示加号,打开手风琴时显示减号

Javascript 如何在引导中为手风琴添加加号或减号?关闭手风琴时显示加号,打开手风琴时显示减号,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我试图将加号和减号添加到bootstrap accordion,当显示内容的div打开时显示加号,当关闭时显示减号,并且当我打开第二个选项卡时,它应该关闭其他打开的选项卡的内容(当前正在发生这种情况),并且它应该将除活动选项卡之外的选项卡的减号图标更改为加号图标 非常感谢能够提供解决方案或方法的任何人:) 在此处输入代码 手风琴示例 注意:数据父项属性确保在显示一个可折叠项时关闭指定父项下的所有可折叠元素 Lorem ipsum dolor sit amet,奉献精英, 这是临时性的劳动和就业机

我试图将加号和减号添加到bootstrap accordion,当显示内容的div打开时显示加号,当关闭时显示减号,并且当我打开第二个选项卡时,它应该关闭其他打开的选项卡的内容(当前正在发生这种情况),并且它应该将除活动选项卡之外的选项卡的减号图标更改为加号图标

非常感谢能够提供解决方案或方法的任何人:)

在此处输入代码
手风琴示例
注意:数据父项属性确保在显示一个可折叠项时关闭指定父项下的所有可折叠元素

Lorem ipsum dolor sit amet,奉献精英, 这是临时性的劳动和就业机会。我们在这里吃得很少, 我们的实验室是一个普通的实验室。 Lorem ipsum dolor sit amet,奉献精英, 这是临时性的劳动和就业机会。我们在这里吃得很少, 我们的实验室是一个普通的实验室。 Lorem ipsum dolor sit amet,奉献精英, 这是临时性的劳动和就业机会。我们在这里吃得很少, 我们的实验室是一个普通的实验室。 jquery代码 $(文档).ready(函数(){ $('.panel title custom').addClass('glyphicon glyphicon plus'); $('.panel title custom')。单击(函数(){ $(this.toggleClass('glyphicon-plus-glyphicon-减号'); }); });
这是您的工作代码

$('#accordion')
  .on('show.bs.collapse', function(e) {   
     $(e.target).prev('.panel-heading-custom').find('div').removeClass('glyphicon glyphicon-plus');        
     $(e.target).prev('.panel-heading-custom').find('div').addClass('glyphicon glyphicon-minus');   
  })
  .on('hide.bs.collapse', function(e) {
   $(e.target).prev('.panel-heading-custom').find('div').removeClass('glyphicon glyphicon-minus');
   $(e.target).prev('.panel-heading-custom').find('div').addClass('glyphicon glyphicon-plus');   
  });
检查下面的JSFIDLE

$('.panel title>a')。单击(函数(){
$(this).parents('.panel default').find('i').toggleClass('fa-plus-fa-减号');
$(this).parents('.panel default')。同胞('.panel default')。find('i')。removeClass('fa-minus')。addClass('fa-plus'))
});

动物保护协会的陈词滥调,埃尼姆·埃乌斯莫德的高寿命accusamus terry richardson广告鱿鱼。3狼月亮奥特餐厅,非丘比特滑板多洛早午餐。食品车奎奴亚藜。早午餐3狼月亮临时,太阳阿利夸放了一只鸟
在它上面,鱿鱼单一来源咖啡Nalla assumenda shoreditch et.Nihil anim keffiyeh helvetica,工艺啤酒工人wes anderson cred Nescuint sapiente ea proident。纯素食主义者,屠夫副洛莫。从工艺啤酒场到餐桌,
粗斜纹棉布美学合成器Nescuint您可能还没有听说过accusamus labore可持续VHS。
动物保护协会的陈词滥调,埃尼姆·埃乌斯莫德的高寿命accusamus terry richardson广告鱿鱼。3狼月亮奥特餐厅,非丘比特滑板多洛早午餐。食品车奎奴亚藜。早午餐3狼月亮临时,太阳阿利夸放了一只鸟
在它上面,鱿鱼单一来源咖啡Nalla assumenda shoreditch et.Nihil anim keffiyeh helvetica,工艺啤酒工人wes anderson cred Nescuint sapiente ea proident。纯素食主义者,屠夫副洛莫。从工艺啤酒场到餐桌,
粗斜纹棉布美学合成器Nescuint您可能还没有听说过accusamus labore可持续VHS。
动物保护协会的陈词滥调,埃尼姆·埃乌斯莫德的高寿命accusamus terry richardson广告鱿鱼。3狼月亮奥特餐厅,非丘比特滑板多洛早午餐。食品车奎奴亚藜。早午餐3狼月亮临时,太阳阿利夸放了一只鸟
在它上面,鱿鱼单一来源咖啡Nalla assumenda shoreditch et.Nihil anim keffiyeh helvetica,工艺啤酒工人wes anderson cred Nescuint sapiente ea proident。纯素食主义者,屠夫副洛莫。从工艺啤酒场到餐桌,
粗斜纹棉布美学合成器Nescuint您可能还没有听说过accusamus labore可持续VHS。

这不需要使用jQuery或javascript。简单的5行css可以帮你做到这一点。对于引导accordion,一个名为aria expanded=“true”/aria expanded=“false”的属性将添加到accordion标题中。你可以根据这个添加css


显示您已经尝试过的内容并给出一些更好的示例。请检查此链接:嗨,
code
$(文档)。就绪(函数(){$('.panel title custom')。addClass('glyphicon glyphicon plus');$('.panel collapse.collapse.in')。同级('.panel heading custom')。查找('h4.panel title custom')。toggleClass('glypicon-plus-glypicon');$('.panel title custom')。单击(function(){$(this)。toggleClass('glypicon-plus-glypicon-plus');$(this)。parents('.panel default')。sides()。find('.panel title custom')。removeClass('glypicon-glypicon-plus')。addClass('glypicon-glypicon-glypicon');););
code
用JSFiddle更新了答案。如果对你有帮助,请用upvote接受答案!@nagrajan Perumal谢谢你的回答,我已经发布了代码,我实现加号和减号的方式,因为,我不熟悉,在这里的评论栏中发布的方式,它已经像普通文本一样粘贴,我为此道歉同样。还有一个问题,关于如何使用on元素触发事件,我对e.target或event.target有点困惑,如果可能的话,可以用几句简单的话在这里介绍一下。启动事件的DOM元素。阅读下面的参考资料,其中清楚地解释了event.target。
$('#accordion')
  .on('show.bs.collapse', function(e) {   
     $(e.target).prev('.panel-heading-custom').find('div').removeClass('glyphicon glyphicon-plus');        
     $(e.target).prev('.panel-heading-custom').find('div').addClass('glyphicon glyphicon-minus');   
  })
  .on('hide.bs.collapse', function(e) {
   $(e.target).prev('.panel-heading-custom').find('div').removeClass('glyphicon glyphicon-minus');
   $(e.target).prev('.panel-heading-custom').find('div').addClass('glyphicon glyphicon-plus');   
  });
.accordion-btn {
 position: relative;
}
.accordion-btn:before {
 position: absolute;
 content: "+";
 right: 10px;
 top: 5px;
}
.accordion-btn[aria-expanded="true"]:before {
 content: "-"; }