本文实例讲述了jquery实现的简单二级菜单效果代码。分享给大家供大家参考。具体如下:
这是一款基于jquery实现的二级菜单,研究了这么多天,才学会用jquery写一个菜单,也算是对自己的鼓励吧,自我感觉这个菜单很不错,欢迎朋友们指点江山。
运行效果截图如下:
在线演示地址如下:
具体代码如下:
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
jquery二级菜单$(function(){
$("#container .menu1 ul li").click(function(){
var index=$("#container .menu1 ul li").index(this);
$(this).addClass("bg").siblings().removeClass();
$("#container .menu2 ul li ul").eq(index).show().parent().siblings("li").children("ul").hide();
})
})
body{ margin:0; padding:0; font-family:"宋体"; font-size:9pt; color:#FFFFFF; font-weight:bold}
#container{ width:800px; height:auto; margin:0 auto; border:1px #1025c0 solid}
#container .menu1{ width:800px; height:40px; border:none; background:url(images/menu1.gif) no-repeat}
#container .menu1 ul{ margin:0; padding:0; position:relative; padding-top:5px;}
#container .menu1 ul li{ float:left; padding-left:10px; height:35px; width:80px; line-height:35px; list-style:none; text-align:center; cursor:pointer}
#container .menu2{ width:800px; height:35px; border:none; background-color:#333333;}
#container .menu2 ul{ margin:0; padding:0}
#container .menu2 ul li{ height:35px; line-height:35px; list-style:none; float:left; cursor:pointer}
#container .menu2 ul li ul li{ float:left; padding-left:20px; height:35px; line-height:35px; list-style:none}
.bg{ background-color:#333333}
.hide{ display:none}
希望本文所述对大家的jquery程序设计有所帮助。