jquery实现二级导航下拉菜单效果实例

  

大家都知道jQuery是一个框架,它对JS进行了封装,使其更方便使用。前面两篇博文分别是用CSS样式和JS实现的,那么这篇就用jQuery来实现二级下拉式菜单。
  

  

使用JQuery实现需要用到的知识有:

  
      <李> 1)使用$(函数(){…})获取到想要作用的HTML元素。   <李> 2)通过使用孩子()方法寻找子元素。   <李> 3)通过使用显示()方法来显示HTML元素。   <李> 4)通过使用隐藏()方法来隐藏HTML元素。   <李> 5)jQuery库引用方法:李   
  

第一种方法:将jQuery库下载到电脑上,然后引,用我下载的是jquery-1.7.1.min.js这个版本。

  

例如:

        & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/jquery/jquery-1.7.1.min.js "祝辞& lt;/script>      

第二种方法:直接引用在线服务器上的jQuery库文件,比如谷歌服务器jQuery库,百度服务器jQuery库等。
  

  

例如:引用百度服务器上的jQuery库文件

        & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/jquery/1.9.0/jquery.js "祝辞& lt;/script>      

接下来看看制作的流程:

  
      <李> 1,调用jQuery库:编写代码,引用jQuery库。由于谷歌已退出大陆,建议使用百度服务器的jQuery库。   <李>注意:百度服务器的jQuery库地址:http://libs.baidu.com/jquery/1.9.0/jquery.js   <李> 2,编写显示子菜单函数,使用美元,并通过类名获取一级菜单,过孩子()找到李的孩子元素ul、使用显示()方法,显示二级菜单。   <李> 3,编写隐藏子菜单函数,使用美元,并通过类名获取一级菜单,过孩子()找到李的孩子元素ul、使用隐藏()方法,隐藏二级菜单。   <李> 4,做浏览器兼容性测试,至少五个浏览器.IE7, 8, 9,火狐,谷歌,2345年浏览器等。   
  

先来看看效果图:
  

  

 jquery实现二级导航下拉菜单效果实例

  

最后我们来看看代码的情况,和前面的区别不大:

  

HTML代码:

        & lt; !DOCTYPE html公共”——//W3C XHTML 1.0//DTD过渡//EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”的在      html & lt;   xmlns=" http://www.w3.org/1999/xhtml "比;      & lt; head>      & lt;元   http-equiv=" - type "   内容=" text/html;charset=gb2312 "/比;      & lt; title>下拉菜单& lt;/title>      & lt;链接   rel="样式表"   type=" text/css "   href=" https://www.yisu.com/zixun/style.css " rel="外部nofollow”/比;      & lt; !——引用百度服务器的jQuery库——比;      & lt;脚本   src=" http://libs.baidu.com/jquery/1.9.0/jquery.js "祝辞& lt;/script>      & lt;脚本   type=" text/javascript "   src=" https://www.yisu.com/zixun/script.js "祝辞& lt;/script>      & lt;/head>      ,,      & lt; body>      & lt; div   id="导航"   类="导航"比;      & lt;才能ul>      ,,,& lt; li> & lt;   href=" https://www.yisu.com/zixun/" rel="外部nofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”在网站首页& lt;/a> & lt;/li>      ,,& lt;李   类=" navmenu "祝辞& lt;   href=" https://www.yisu.com/zixun/" rel="外部nofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”在课程大厅& lt;/a>      ,,,& lt; ul>      ,,,,& lt; li> & lt;   href=" https://www.yisu.com/zixun/" rel="外部nofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”祝辞JavaScript & lt;/li>      ,,,,& lt; li> & lt;   href=" https://www.yisu.com/zixun/" rel="外部nofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”rel=巴獠縩ofollow”祝辞jQuery

jquery实现二级导航下拉菜单效果实例