如果想像你这样实现,最好在每一个ul和li加上ID(这个ID必须是有规律的,比如父ID为1_1,子ID1_1_1...),用链接的点击事件根据ID获取父菜单和子菜单实现改变ul、li的display样式就可以实现展开或隐藏。
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<script>
jQuery(function($){
$("ul>li>a").click(function(){
$(this).next("ul").toggle().closest("li").siblings("li").children("ul").hide()
}).next("ul").hide()
})
</script>
</head>
<body>
<ul>
<li>
<a>
一级菜单
</a>
<ul>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
</ul>
</li>
<li>
<a>
一级菜单
</a>
<ul>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
</ul>
</li>
<li>
<a>
一级菜单
</a>
<ul>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
<li>
隐藏的二级菜单项
</li>
</ul>
</li>
</ul>
</body>
</html>
<li class="submenu"><a class="dropdown " href="javascript:showMenu(1)" data-original-title="主菜单1"><span aria-hidden="true" class="icon icon-magnifier-add"></span><span class="hidden-minibar "> 主菜单1</span><span class="fa arrow"></span></a><ul style="display: none" id="ul1">
<li><a href="/agent/Order.asp" data-original-title="子菜单1"><span class="hidden-minibar "> 子菜单1</span></a></li>
<li><a href="/agent/OrderBuy.asp" data-original-title="子菜单2"><span class="hidden-minibar "> 子菜单2</span></a></li>
<li><a href="/agent/tkinfo.asp" data-original-title="子菜单3"><span class="hidden-minibar "> 子菜单3</span></a></li>
</ul>
</li>
<li class="submenu"><a class="dropdown " href="javascript:showMenu(2)" data-original-title="主菜单2"><span aria-hidden="true" class="icon icon-magnifier-add"></span><span class="hidden-minibar "> 主菜单2</span><span class="fa arrow"></span></a>
<ul style="display: none" id="ul2">
<li><a href="/agent/Order.asp" data-original-title="子菜单1"><span class="hidden-minibar "> 子菜单1</span></a></li>
<li><a href="/agent/OrderBuy.asp" data-original-title="子菜单2"><span class="hidden-minibar "> 子菜单2</span></a></li>
<li><a href="/agent/tkinfo.asp" data-original-title="子菜单3"><span class="hidden-minibar "> 子菜单3</span></a></li>
</ul>
</li>
<script>
function showMenu(s){
if(s == 1){
document.getElementById("ul1").style.display="block"
document.getElementById("ul2").style.display="none"
}else if(s == 2){
document.getElementById("ul2").style.display="block"
document.getElementById("ul1").style.display="none"
}
}
</script>
这样就行了