书写好html内容然后引入jQuery和css样式
<script src="jquery 2.1.4.js"></script> <link rel="stylesheet" href="style.css">样式内容如下: body{ margin: 0; padding: 0; } .ucls{ list-style: none; display: none; clear: both; } .ucls li{ width: 200px; height: 30px; line-height: 30px; background: #c0c; margin: 2px; text-align: center; } .dcls{ width: 200px; } .hcls{ width: 200px; height: 40px; line-height: 40px; background: #ccc; margin: 2px; padding: 0; float: left; text-align: center; cursor: pointer; } 效果如图所示:最后加入js代码:
<script type="text/javascript"> $('.ucls').eq(0).css('display','block'); <span style="white-space:pre"> </span>//打开页面时展开第一个导航栏子菜单 $('.hcls').each(function(i){ $(this).click(function(){ $('.ucls').eq(i).slideDown(800).siblings('ul').slideUp(800);<span style="white-space:pre"></span><pre name="code" class="javascript"> <span style="white-space:pre"> </span>//点击导航栏时展开对应的导航栏子菜单,并收起其他的子菜单});});</script> 效果如图: 相关资源:JQuery实现横纵向下拉菜单