我正在做一个菜单,每个项目都有它的子菜单。这是标记:
<ul id="menu">
<li>
<a href="javascript:void(0)" onclick="show_submenu(this)">TITLE 1</a>
<ul class="submenu">
<li>
<a href="javascript:void(0)">sub1</a>
</li>
<li>
<a href="javascript:void(0)">sub2</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)">TITLE 2</a>
<ul class="submenu">
<li>
<a href="javascript:void(0)">sub1</a>
</li>
<li>
<a href="javascript:void(0)">sub2</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)">TITLE 3</a>
</li>
<li>
<a href="javascript:void(0)">TITLE 4</a>
</li>
</ul>
css
.submenu{display:none}
脚本
function show_submenu(that) {
$('ul.submenu').slideUp();
$(that).next('ul.submenu:first').slideDown();
}
我遇到的问题是,如果我点击一个项目,它会向下滑动它的子菜单,但是如果我再次点击它,它会再次向上滑动和向下滑动它的子菜单,它已经打开了......有点奇怪的效果对于用户...任何想法如何解决它?