再会!根据我从您的问题中了解到的情况,我是这样做的:
HTML 标记
<ul>
<li>
<span>value 1</span>
<ul>
<li>
<span>inner value 1</span>
<ul>
<li>inner inner value 1</li>
<li>inner inner value 2</li>
<li>inner inner value 3</li>
</ul>
</li>
<li>
<span>inner value 2</span>
<ul>
<li>inner inner value 1</li>
<li>inner inner value 2</li>
<li>inner inner value 3</li>
</ul>
</li>
<li>
<span>inner value 3</span>
<ul>
<li>inner inner value 1</li>
<li>inner inner value 2</li>
<li>inner inner value 3</li>
</ul>
</li>
</ul>
</li>
<li>
<span>value 2</span>
<ul>
<li>inner value 1</li>
<li>inner value 2</li>
<li>inner value 3</li>
</ul>
</li>
<li>
<span>value 3</span>
<ul>
<li>inner value 1</li>
<li>inner value 2</li>
<li>inner value 3</li>
</ul>
</li>
</ul>
CSS
li > ul {
display: none;
}
jQuery
$("ul > li").has("> ul").click(function(e) {
e.stopPropagation();
$(this).find("> ul").slideToggle();
$(this).siblings("li").find("> ul").slideUp();
});
$("ul > li").click(function(e) {
e.stopPropagation();
});