Jquery 如何折叠手风琴标签?
目前,我已经设置了一个手风琴页面,所以当你点击每个手风琴选项卡时,它会折叠上面或下面的页面 我想实现的是,你可以点击一个手风琴标签,打开它,然后关闭它 我的HTML如下所示:Jquery 如何折叠手风琴标签?,jquery,html,css,Jquery,Html,Css,目前,我已经设置了一个手风琴页面,所以当你点击每个手风琴选项卡时,它会折叠上面或下面的页面 我想实现的是,你可以点击一个手风琴标签,打开它,然后关闭它 我的HTML如下所示: <dl class="accordion"> <dt class="title"> <p>Accordion 1</p> </dt> <dd>
<dl class="accordion">
<dt class="title">
<p>Accordion 1</p>
</dt>
<dd>
<p>Some text for the accordion here...</p>
</dd>
<dt class="title">
<p>Accordion 2</p>
</dt>
<dd>
<p>Some text for the accordion here...</p>
</dd>
<dt class="title">
<p>Accordion 3</p>
</dt>
<dd>
<p>Some text for the accordion here...</p>
</dd>
<dt class="title">
<p>Accordion 4</p>
</dt>
<dd>
<p>Some text for the accordion here...</p>
</dd>
</dl>
如果使用jQueryUIAccordion,只需在init上将可折叠选项设置为true,如
$(document).ready(function(){
$('.accordion').accordion({collapsible:true});
});
如果不使用jQueryUIAccordion,也许您应该;)
如果使用jQuery UI accordion,只需在init上将可折叠选项设置为true,如
$(document).ready(function(){
$('.accordion').accordion({collapsible:true});
});
如果不使用jQueryUIAccordion,也许您应该;)
如果使用jQuery UI accordion,只需在init上将可折叠选项设置为true,如
$(document).ready(function(){
$('.accordion').accordion({collapsible:true});
});
如果不使用jQueryUIAccordion,也许您应该;)
如果使用jQuery UI accordion,只需在init上将可折叠选项设置为true,如
$(document).ready(function(){
$('.accordion').accordion({collapsible:true});
});
如果不使用jQueryUIAccordion,也许您应该;)
您检查元素是否具有活动的类
accordition
,因此添加else
部分
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
$this.removeClass('accordition-active');
$this.parent().children('dd').slideUp();
}
您检查元素是否具有活动的类
accordition
,因此添加else
部分
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
$this.removeClass('accordition-active');
$this.parent().children('dd').slideUp();
}
您检查元素是否具有活动的类
accordition
,因此添加else
部分
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
$this.removeClass('accordition-active');
$this.parent().children('dd').slideUp();
}
您检查元素是否具有活动的类
accordition
,因此添加else
部分
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
$this.removeClass('accordition-active');
$this.parent().children('dd').slideUp();
}
您可以尝试以下方法:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dd:first-of-type').show();
$('.accordion > dt:first-of-type').addClass('accordion-active');
jQuery('.accordion > dt').on('click', function() {
$this = $(this);
$target = $this.next();
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
jQuery('.accordion > dt').removeClass('accordion-active');
$this.parent().children('dd').slideUp();
}
return false;
});
})(jQuery);
此代码打开和折叠手风琴
其他方面,您可以使用jQueryUI插件。您可以尝试以下方法:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dd:first-of-type').show();
$('.accordion > dt:first-of-type').addClass('accordion-active');
jQuery('.accordion > dt').on('click', function() {
$this = $(this);
$target = $this.next();
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
jQuery('.accordion > dt').removeClass('accordion-active');
$this.parent().children('dd').slideUp();
}
return false;
});
})(jQuery);
此代码打开和折叠手风琴
其他方面,您可以使用jQueryUI插件。您可以尝试以下方法:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dd:first-of-type').show();
$('.accordion > dt:first-of-type').addClass('accordion-active');
jQuery('.accordion > dt').on('click', function() {
$this = $(this);
$target = $this.next();
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
jQuery('.accordion > dt').removeClass('accordion-active');
$this.parent().children('dd').slideUp();
}
return false;
});
})(jQuery);
此代码打开和折叠手风琴
其他方面,您可以使用jQueryUI插件。您可以尝试以下方法:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dd:first-of-type').show();
$('.accordion > dt:first-of-type').addClass('accordion-active');
jQuery('.accordion > dt').on('click', function() {
$this = $(this);
$target = $this.next();
if(!$this.hasClass('accordion-active')){
$this.parent().children('dd').slideUp();
jQuery('.accordion > dt').removeClass('accordion-active');
$this.addClass('accordion-active');
$target.addClass('active').slideDown();
} else {
jQuery('.accordion > dt').removeClass('accordion-active');
$this.parent().children('dd').slideUp();
}
return false;
});
})(jQuery);
此代码打开和折叠手风琴
其他方面,您可以使用jQueryUI插件。
(函数($){
$('.accordion>dd').hide();
$('.accordion>dd.active').show();
$('.accordion>dt')。打开(“单击”,函数(事件){
$(“dt”).removeClass(“活动”);
$this=this.className;
$(此).addClass(“活动”);
$target=(“dd.”+$this+”);
$(“dd”).removeClass('active').slideUp();
$($target).addClass('active').slideDown();
返回false;
});
})(jQuery)代码>
.手风琴{
显示:内联块;
保证金:0;
列表样式:无;
位置:相对位置;
背景色:#fff;
填充:10px 12px;
}
.手风琴dt.active{
背景色:#eee;
}
.手风琴{
填充:15px;
背景色:#eee;
边框底部:4px实心#D6;
边框右下半径:4px;
边框左下半径:4px;
边际:0px;
}
@仅介质屏幕和(最大宽度:736px){
.手风琴{
/*宽度:100%*/
}
}
表1标题
苏哈尔铝业整体战略的一部分是促进和支持在阿曼建立一个强大的下游铝工业,以增加铝生产对阿曼经济的价值,并创造进一步的就业和商业机会。苏哈尔铝业帮助建立了两个下游公司,并向其供应产品正在运行。这些是:
表2标题
苏哈尔铝业整体战略的一部分是促进和支持在阿曼建立一个强大的下游铝工业,以增加铝生产对阿曼经济的价值,并创造进一步的就业和商业机会。苏哈尔铝业帮助建立了两个下游公司,并向其供应产品正在运行。这些是:
表3标题
直接出售给下游的液体量将逐年增加,预计2016年将达到200000吨,国家价值将增加。Sohar铝业的长期计划是将其60%的产量以铁水形式供应给下游合作伙伴,而其余将以固态锭和SOW形式出口
表4标题
直接出售给下游的液体量将逐年增加,预计2016年将达到200000吨,国家价值将增加。Sohar铝业的长期计划是将其60%的产量以铁水形式供应给下游合作伙伴,而其余将以固态锭和SOW形式出口
(函数($){
$('.accordion>dd').hide();
$('.accordion>dd.active').show();
$('.accordion>dt')。打开(“单击”,函数(事件){
$(“dt”).removeClass(“活动”);
$this=this.className;
$(此).addClass(“活动”);
$target=(“dd.”+$this+”);
$(“dd”).removeClass('active').slideUp();
$($target).addClass('active').slideDown();
返回false;
});
})(jQuery)代码>
.手风琴{
显示:内联块;
保证金:0;
列表样式:无;
位置:相对位置;
背景色:#fff;
填充:10px 12px;
}
.手风琴dt.active{
背景色:#eee;
}
.手风琴{
填充:15px;
背景色:#eee;
边框底部:4px实心#D6;
边框右下半径:4px;
边框左下半径:4px;
边际:0px;
}
@仅介质屏幕和(最大宽度:736px){
.手风琴{
/*宽度:100%*/
}
}
表1标题
苏哈尔铝业整体战略的一部分是促进和支持在阿曼建立一个强大的下游铝工业,以增加铝生产对阿曼经济的价值,并创造进一步的就业和商业机会。苏哈尔铝业帮助建立了两个下游公司,并向其供应产品正在运行。这些是:
表2标题
苏哈尔铝业的整体战略的一部分是