时间:2021-05-26
大家都知道jQuery是一个框架,它对JS进行了封装,使其更方便使用。前面两篇博文分别是用CSS样式和JS实现的,那么这篇就用jQuery来实现二级下拉式菜单。
使用JQuery实现需要用到的知识有:
第一种方法:将jQuery库下载到电脑上,然后引用,我下载的是jquery-1.7.1.min.js这个版本。
例如:
<script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script>第二种方法:直接引用在线服务器上的jQuery库文件,比如谷歌服务器jQuery库,百度服务器jQuery库等。
例如:引用百度服务器上的jQuery库文件
<script type="text/javascript" src="jquery/1.9.0/jquery.js"></script>接下来看看制作的流程:
先来看看效果图:
最后我们来看看代码的情况,和前面的区别不大:
HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///jquery/1.9.0/jquery.js"></script><scripttype="text/javascript"src="script.js"></script></head><body><divid="nav"class="nav"><ul><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >网站首页</a></li><liclass="navmenu"><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >课程大厅</a><ul><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >JavaScript</a></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jQuery</a></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Ajax</a></li></ul></li><liclass="navmenu"><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >学习中心</a><ul><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >视频学习</a></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >案例学习</a></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >交流平台</a></li></ul></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >经典案例</a></li><li><ahref="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >关于我们</a></li></ul></div></body></html>CSS样式表外部style.css文件代码:
*{margin:0;padding:0;}.nav{background-color:#EEEEEE;height:40px;width:450px;margin:0auto;}ul{list-style:none;}ul li{float:left;line-height:40px;text-align:center;}a{text-decoration:none;color:#000000;display:block;width:90px;height:40px;}a:hover{background-color:#666666;color:#FFFFFF;}ul li ul li{float:none;background-color:#EEEEEE;}ul li ul{display:none;}ul li ul li a:link,ul li ul li a:visited{background-color:#EEEEEE;}ul li ul li a:hover{background-color:#009933;}JS脚本外部script,js文件代码:
$(function(){$(".navmenu").mouseover(function(){$(this).children("ul").show();})$(".navmenu").mouseout(function(){$(this).children("ul").hide();})})以上所述是小编给大家介绍的jquery二级导航下拉菜单详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了jquery实现简单的二级导航下拉菜单效果。分享给大家供大家参考。具体如下:jQuery代码实现的二级导航菜单效果,非常简洁,喜欢简洁风格的朋友您
本文实例讲述了jquery实现鼠标滑过显示二级下拉菜单效果。分享给大家供大家参考。具体如下:这是一款jquery实现的下拉菜单,当鼠标移在主菜单上的时候,向下滑
本文实例讲述了jQuery实现带动画效果的二级下拉导航方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:jQuery二级下滑导菜单body{fon
本文实例讲述了CSS实现的灰色下拉菜单效果代码。分享给大家供大家参考。具体如下:这是一款基于CSS实现的灰色下拉菜单,支持二级的导航菜单,如果不喜欢灰色的话,颜
本文实例讲述了JS+CSS实现简单的二级下拉导航菜单效果。分享给大家供大家参考。具体如下:这是一款CSS配合JavaScript实现二级下拉导航菜单,好像CSS