我创建了一个简单的手风琴菜单。我的问题是当我单击“Folder1”时它会展开,但是当我再次单击它时它应该崩溃..我被困住了,无法进行任何帮助..
JsFiddle - http://jsfiddle.net/nY2t7/
$(document).ready(function() {
$('#content >li').each(function(i){
hideElements($(this));
});
$('#content').click(function(event) {
$x = $(event.target);
//check if the element is the root node if so then hide all other li's and reveal the current one
if($x.parent().is('ul#content')) {
if($x.is(':visible')) { //check if its already expanded .. if so then collapse and return
$x.find('ul >li').slideUp(300 , function() {
**//return;** does not work
});
}
$('#content ul>li').each(function(i){
collapseElements($(this));
});
}
if($x.is('li'))
$x.find('ul:first > li').slideToggle(300);
});
function collapseElements(el) {
if(el.is(':visible')) {
el.slideUp(300);
}
}
function hideElements(elem) {
elem.find('ul >li').hide();
//$($e >li).hide();
}
});