我不知道我是否理解你的问题。但这里是我将如何完成的代码。
<ul id="accordion">
<li>
<a href="#recent" class="heading">Application</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Forum</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Guilds</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Projects</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
CSS
ul#accordion{
float:right;
}
ul#accordion, ul#accordion ul { list-style: none; margin: 0; }
ul#accordion a.heading {
color: black;
display: block;
font-size:16px;
font-weight:bold;
text-decoration: none;
margin-right:30px;
}
ul#accordion li ul a { font-size:14px;color: black; text-decoration: none;}
ul#accordion li ul a:hover { text-decoration: underline; }
#accordion li ul { display: none; }
#accordion li.current ul { display: block; }
JS
$(document).ready(function() {
$('ul#accordion a.heading').click(function() {
$(this).css('outline','none');
if($(this).parent().hasClass('current')) {
$(this).siblings('ul').slideUp('slow',function() {
$(this).parent().removeClass('current');
});
} else {
$('ul#accordion li.current ul').slideUp('slow',function() {
$(this).parent().removeClass('current');
});
$(this).siblings('ul').slideToggle('slow',function() {
$(this).parent().toggleClass('current');
});
}
return false;
});
});
这是一个jsFiddle