最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery實(shí)現(xiàn)二級(jí)導(dǎo)航下拉菜單效果實(shí)例

 更新時(shí)間:2019年05月14日 15:32:03   作者:Alvin哥哥  
這篇文章主要介紹了jquery二級(jí)導(dǎo)航下拉菜單,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

大家都知道jQuery是一個(gè)框架,它對(duì)JS進(jìn)行了封裝,使其更方便使用。前面兩篇博文分別是用CSS樣式和JS實(shí)現(xiàn)的,那么這篇就用jQuery來實(shí)現(xiàn)二級(jí)下拉式菜單。

使用JQuery實(shí)現(xiàn)需要用到的知識(shí)有:

  1. 1)使用$(function(){...})獲取到想要作用的HTML元素。
  2. 2)通過使用children()方法尋找子元素。
  3. 3)通過使用show()方法來顯示HTML元素。
  4. 4)通過使用hide()方法來隱藏HTML元素。
  5. 5)jQuery庫(kù)引用方法:

第一種方法:將jQuery庫(kù)下載到電腦上,然后引用,我下載的是jquery-1.7.1.min.js這個(gè)版本。

例如: 

<script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script>

第二種方法:直接引用在線服務(wù)器上的jQuery庫(kù)文件,比如谷歌服務(wù)器jQuery庫(kù),百度服務(wù)器jQuery庫(kù)等。

例如:引用百度服務(wù)器上的jQuery庫(kù)文件

<script type="text/javascript" src="jquery/1.9.0/jquery.js"></script>

接下來看看制作的流程:

  1. 1、調(diào)用jQuery庫(kù):編寫代碼,引用jquery庫(kù)。由于谷歌已退出大陸,建議使用百度服務(wù)器的jQuery庫(kù)。
  2. 注意: 百度服務(wù)器的jQuery庫(kù)地址:http://libs.baidu.com/jquery/1.9.0/jquery.js
  3. 2 、編寫顯示子菜單函數(shù),使用$,并通過class名獲取一級(jí)菜單li,過children()找到li的孩子元素ul,使用show()方法,顯示二級(jí)菜單。
  4. 3、編寫隱藏子菜單函數(shù),使用$,并通過class名獲取一級(jí)菜單li,過children()找到li的孩子元素ul,使用hide()方法, 隱藏二級(jí)菜單。
  5. 4、做瀏覽器兼容性測(cè)試,至少五個(gè)瀏覽器。IE7,8,9,火狐,谷歌,2345瀏覽器等。

先來看看效果圖:

最后我們來看看代碼的情況,和前面的區(qū)別不大:

HTML代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html
xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta
http-equiv="Content-Type"
content="text/html; charset=gb2312" />

<title>下拉菜單</title>

<link
rel="stylesheet"
type="text/css"
href="style.css" rel="external nofollow" 
/>

<!--引用百度服務(wù)器的jQuery庫(kù)-->

<script
src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>

<script
type="text/javascript"
src="script.js"></script>

</head>

  

<body>

<div
id="nav"
class="nav">

  <ul>

    <li><a
href="#" 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" >網(wǎng)站首頁(yè)</a></li>

   <li
class="navmenu"><a
href="#" 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><a
href="#" 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><a
href="#" 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><a
href="#" 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>

   <li
class="navmenu"><a
href="#" 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" >學(xué)習(xí)中心</a>

    <ul>

     <li><a
href="#" 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" >視頻學(xué)習(xí)</a></li>

     <li><a
href="#" 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" >案例學(xué)習(xí)</a></li>

     <li><a
href="#" 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" >交流平臺(tái)</a></li>

    </ul>

   </li>

   <li><a
href="#" 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" >經(jīng)典案例</a></li>

   <li><a
href="#" 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" >關(guān)于我們</a></li>

  </ul>

</div>

</body>

</html>

CSS樣式表外部style.css文件代碼:

/*CSS全局設(shè)置*/

*{

 margin:0;

 padding:0;

}

.nav{

 background-color:#EEEEEE;

 height:40px;

 width:450px;

 margin:0
auto;

}

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;

}

/*為了兼容IE7寫的CSS樣式,但是必須寫在a:hover前面*/

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二級(jí)導(dǎo)航下拉菜單詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 關(guān)于jquery ajax 調(diào)用帶參數(shù)的webservice返回XML數(shù)據(jù)一個(gè)小細(xì)節(jié)

    關(guān)于jquery ajax 調(diào)用帶參數(shù)的webservice返回XML數(shù)據(jù)一個(gè)小細(xì)節(jié)

    很早之前用jquery調(diào)用帶參數(shù)的WS返回XML格式數(shù)據(jù)的時(shí)候,傳參的時(shí)候會(huì)出現(xiàn)錯(cuò)誤。問了問度娘和谷哥,這娘兒倆一個(gè)德行,里面的多數(shù)帖子沒什么意義,你粘我,我復(fù)制你
    2012-07-07
  • jQuery ready()和onload的加載耗時(shí)分析

    jQuery ready()和onload的加載耗時(shí)分析

    這篇文章主要介紹了jQuery ready()和onload的加載耗時(shí),結(jié)合實(shí)例形式對(duì)比分析了jQuery中的ready()和JavaScript的window.onload進(jìn)行頁(yè)面加載的時(shí)間,需要的朋友可以參考下
    2016-09-09
  • 使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法

    使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法

    這篇文章主要介紹了使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法,涉及jquery使用表單插件jquery.form.js進(jìn)行圖片上傳的提交、類型驗(yàn)證、執(zhí)行結(jié)果回調(diào)顯示等技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2016-05-05
  • jQuery中(function(){})()執(zhí)行順序的理解

    jQuery中(function(){})()執(zhí)行順序的理解

    function的順序是這樣的:先計(jì)算第一個(gè)小括號(hào),發(fā)現(xiàn)里面的表達(dá)式是一個(gè)函數(shù),返會(huì)該匿名函數(shù)的引用(指針),最后一個(gè)括號(hào)則是建立匿名函數(shù)的實(shí)參和并執(zhí)行,感興趣的你可以參考下本文
    2013-03-03
  • JQuery 傳送中文亂碼問題的簡(jiǎn)單解決辦法

    JQuery 傳送中文亂碼問題的簡(jiǎn)單解決辦法

    下面小編就為大家?guī)硪黄狫Query 傳送中文亂碼問題的簡(jiǎn)單解決辦法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-05-05
  • 詳解jQuery中的事件

    詳解jQuery中的事件

    jQuery增加了并擴(kuò)展了基本的事件處理機(jī)制,不但提供了更加優(yōu)雅的事件處理語(yǔ)法,而且極大地增強(qiáng)了事件處理能力。本文將對(duì)此進(jìn)行詳細(xì)介紹,需要的朋友一起來看下吧
    2016-12-12
  • jQuery.event兼容各瀏覽器的event詳細(xì)解析

    jQuery.event兼容各瀏覽器的event詳細(xì)解析

    jQuery在遵循W3C規(guī)范的情況下,對(duì)事件的常用屬性進(jìn)行了封裝,使得事件處理在各大瀏覽器下都可以正常的運(yùn)行而不需要進(jìn)行瀏覽器類型判斷
    2013-12-12
  • jquery css 選擇器演示代碼

    jquery css 選擇器演示代碼

    這篇文章對(duì)于剛開始學(xué)習(xí)jquery的css 選擇器的朋友是個(gè)不錯(cuò)的參考,大家可以看實(shí)例演示即可。
    2010-05-05
  • Ext.get() 和 Ext.query()組合使用實(shí)現(xiàn)最靈活的取元素方式

    Ext.get() 和 Ext.query()組合使用實(shí)現(xiàn)最靈活的取元素方式

    想要利用ExtJS的庫(kù)函數(shù)對(duì)DOM進(jìn)行各類操作,就要得到Element類型的對(duì)象,但是Ext.get()取到的雖然是Element,但是參數(shù)只能是id,如果大家對(duì)jQuery的selector方式很喜歡和崇拜,那么就一定要學(xué)習(xí)Ext.get()和Ext.query()的組合方式。
    2011-09-09
  • jQuery技巧總結(jié)

    jQuery技巧總結(jié)

    隨著WEB2.0及ajax思想在互聯(lián)網(wǎng)上的快速發(fā)展傳播,陸續(xù)出現(xiàn)了一些優(yōu)秀的Js框架,其中比較著名的有Prototype、YUI、jQuery、mootools、Bindows以及國(guó)內(nèi)的JSVM框架等
    2011-01-01

最新評(píng)論

亳州市| 阜宁县| 肥乡县| 宜兰县| 客服| 东城区| 综艺| 芜湖县| 三门县| 安庆市| 双牌县| 河间市| 万安县| 积石山| 高安市| 旺苍县| 正蓝旗| 肇庆市| 和林格尔县| 盐津县| 马尔康县| 武川县| 绥德县| 龙川县| 晋宁县| 邹平县| 临泉县| 张家界市| 化州市| 阿荣旗| 曲沃县| 清镇市| 祁门县| 句容市| 九台市| 张掖市| 崇州市| 塔城市| 会昌县| 兴文县| 林芝县|