我正在尝试将手风琴嵌套在手风琴中,我需要一些帮助。经过几次尝试,我最终得到了一个嵌套的手风琴,但是当点击它时,它并没有打开它,而是关闭并恢复到开头。任何帮助将不胜感激。
标记示例
<div id="accordion-container">
<h2 class="accordion-header">Section 1</h2>
<div class="accordion-content">
<div id="accordion-container">
<h2 class="accordion-header">Nested1 1</h2>
<div class="accordion-content">
<p>Nested 1 Content</p>
</div>
<h2 class="accordion-header">Nested 2</h2>
<div class="accordion-content">
<p>Nested 2 Content</p>
</div>
</div>
</div>
<h2 class="accordion-header">Section 2</h2>
<div class="accordion-content">
<p>Section 2 Content</p>
</div>
</div>
和jQuery
$(document).ready(function()
{
//Add Inactive Class To All Accordion Headers
$('.accordion-header').toggleClass('inactive-header');
//Set The Accordion Content Width
var contentwidth = $('.accordion-header').width();
$('.accordion-content').css({'width' : contentwidth });
//Open The First Accordion Section When Page Loads
$('.accordion-header').first().toggleClass('active-header').toggleClass('inactive- header');
$('.accordion-content').first().slideDown().toggleClass('open-content');
// The Accordion Effect
$('.accordion-header').click(function () {
if($(this).is('.inactive-header')) {
$('.active-header').toggleClass('active-header').toggleClass('inactive-header').next().slideToggle().toggleClass('open-content');
$(this).toggleClass('active-header').toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
}
else {
$(this).toggleClass('active-header').toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
}
});
return false;
});