http://jsfiddle.net/buhlett/paw5w/
手风琴工作顺利,但它不允许我在任何时候关闭所有面板。一个面板始终被强制打开。
我很确定我错过了一两行
jQuery
$(document).ready(function() {
// Store variables
var accordion_head = $('.grape-accordion > li > a'),
accordion_body = $('.grape-accordion li > .grape-sub-menu, .grape-last-sub-menu');
// Open the first tab on load
// Click function
accordion_head.on('click', function(event) {
// Disable header links
event.preventDefault();
// Show and hide the tabs on click
if ($(this).attr('class') != 'active') {
accordion_body.slideUp('normal');
$(this).next().stop(true, true).slideToggle('normal');
accordion_head.removeClass('active');
$(this).addClass('active');
}
});
});
HTML
<div>
<ul class="grape-accordion">
<li id="one" class="share"><a href="#one">-</a>
<ul class="grape-sub-menu">
<li><a href="#"><em>»</em>-</a></li>
</ul>
</li>
<li id="two" class="mail"><a href="#two">-</a>
<ul class="grape-sub-menu">
<li><a href="#"><em>»</em>-</a></li>
</ul>
</li>
<li id="two" class="mail"><a href="#two">-</a>
<ul class="grape-sub-menu">
<li><a href="#"><em>»</em>-</a></li>
</ul>
</li>
</ul>
</div>