本文實例講述了jQuery實現簡單的下拉菜單導航功能。分享給大家供大家參考,具體如下:
先來看看運行效果:
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>www.gxlcms.com jQuery導航</title> <style type="text/css"> #menu{width:300px;margin-left:auto;margin-right:auto;}.has_children{background:#555;color:#fff;cursor:pointer;}.highlight{color:#fff;background:green;} div{padding:0;} div a{background:#888;display:none;float:left;width:300px;} </style> <!-- 引入 jQuery --> <script src="jquery1.3.2.js" type="text/javascript"></script> <script type="text/javascript"> //等待dom元素加載完畢. $(document).ready(function(){ $(".has_children").click(function(){ $(this).addClass("highlight") //為當前元素增加highlight類 .children("a").show().end() //將子節點的a元素顯示出來并重新定位到上次操作的元素 .siblings().removeClass("highlight") //獲取元素的兄弟元素,并去掉他們的highlight類 .children("a").hide(); //將兄弟元素下的a元素隱藏 }); }); </script> </head> <body> <div id="menu"> <div class="has_children"> <span>第1章-認識jQuery</span> <a>1.1-JavaScript和JavaScript庫</a> <a>1.2-加入jQuery</a> <a>1.3-編寫簡單jQuery代碼</a> <a>1.4-jQuery對象和DOM對象</a> <a>1.5-解決jQuery和其它庫的沖突</a> <a>1.6-jQuery開發工具和插件</a> <a>1.7-小結</a> </div> <div class="has_children"> <span>第2章-jQuery選擇器</span> <a>2.1-jQuery選擇器是什么</a> <a>2.2-jQuery選擇器的優勢</a> <a>2.3-jQuery選擇器</a> <a>2.4-應用jQuery改寫示例</a> <a>2.5-選擇器中的一些注意事項</a> <a>2.6-案例研究——類似淘寶網品牌列表的效果</a> <a>2.7-還有其它選擇器么?</a> <a>2.8-小結</a> </div> <div class="has_children"> <span>第3章-jQuery中的DOM操作</span> <a>3.1-DOM操作的分類</a> <a>3.2-jQuery中的DOM操作</a> <a>3.3-案例研究——某網站超鏈接和圖片提示效果</a> <a>3.4-小結</a> </div> </div> </body> </html>
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery拖拽特效與技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com