jQuery實現(xiàn)導(dǎo)航欄頭部菜單項點擊后變換顏色的方法
本文實例講述了jQuery實現(xiàn)導(dǎo)航欄頭部菜單項點擊后變換顏色的方法。分享給大家供大家參考,具體如下:
實現(xiàn)效果如下:
話不多說直接上代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> a{ text-decoration: none; color: black; } #menu{ width: 100%; height: 20px; background: gainsboro; } ul li{ list-style: none; float: left; padding-left: 20px; background-color: whitesmoke; } .active { color: white; background-color: black; } .none { background-color: whitesmoke; } </style> </head> <body> <ul id="menu"> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >直播</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >新聞</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >關(guān)于</a></li> </ul> <script src="jquery-1.7.2.min.js"></script> <script> $('#menu li a').click(function () { var f = this; $('#menu li a').each(function () { this.className = this == f ? 'active' : 'none' }); }); </script> </body> </html>
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- 簡單的jquery左側(cè)導(dǎo)航欄和頁面選中效果
- JQuery 浮動導(dǎo)航欄實現(xiàn)代碼
- 用jquery的方法制作一個簡單的導(dǎo)航欄
- Jquery給當前頁或者跳轉(zhuǎn)后頁面的導(dǎo)航欄添加選中后樣式的實例
- jquery實現(xiàn)鼠標點擊后展開列表內(nèi)容的導(dǎo)航欄效果
- jquery+css實現(xiàn)側(cè)邊導(dǎo)航欄效果
- jQuery Mobile 導(dǎo)航欄代碼
- jQuery點擊導(dǎo)航欄選中更換樣式的實現(xiàn)代碼
- jquery實現(xiàn)垂直和水平菜單導(dǎo)航欄
- jQuery實現(xiàn)帶展開動畫的導(dǎo)航欄效果
相關(guān)文章
利用jQuery+localStorage實現(xiàn)一個簡易的計時器示例代碼
這篇文章主要給大家介紹了關(guān)于利用jQuery+localStorage實現(xiàn)一個簡易的計時器的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-12-12超級有用的13個基于jQuery的內(nèi)容滾動插件和教程
這篇文章與大家分享13個超級有用的 jQuery 內(nèi)容滾動插件和教程。您可能經(jīng)常能看到一些網(wǎng)站上特色區(qū)域的內(nèi)容以滾動方式變化,這是一種在有限的網(wǎng)頁空間內(nèi)展示更多內(nèi)容的良好方式,而且能吸引用戶注意力。2011-07-07jQuery拖動div、移動div、彈出層實現(xiàn)原理及示例
正如標題所言的實現(xiàn)原理是使div的position為絕對定位absolute,然后控制其top與left值,需要的朋友可以參考下2014-04-04jQuery實現(xiàn)在HTML文檔加載完畢后自動執(zhí)行某個事件的方法
這篇文章主要介紹了jQuery實現(xiàn)在HTML文檔加載完畢后自動執(zhí)行某個事件的方法,結(jié)合實例形式分析了document的ready()事件自動加載執(zhí)行事件的相關(guān)操作技巧,需要的朋友可以參考下2017-05-05Jquery和JS獲取ul中l(wèi)i標簽的實現(xiàn)方法
下面小編就為大家?guī)硪黄狫query和JS獲取ul中l(wèi)i標簽的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06jQuery實現(xiàn)的類似淘寶網(wǎng)站搜索框樣式代碼分享
這篇文章主要介紹了類似淘寶網(wǎng)站搜索框樣式實現(xiàn)代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08JQuery Ajax執(zhí)行跨域請求數(shù)據(jù)的解決方案
今天小編就為大家分享一篇關(guān)于JQuery Ajax執(zhí)行跨域請求數(shù)據(jù)的解決方案,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12