jQuery實(shí)現(xiàn)導(dǎo)航欄頭部菜單項(xiàng)點(diǎn)擊后變換顏色的方法
本文實(shí)例講述了jQuery實(shí)現(xiàn)導(dǎo)航欄頭部菜單項(xiàng)點(diǎn)擊后變換顏色的方法。分享給大家供大家參考,具體如下:
實(shí)現(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擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- 簡(jiǎn)單的jquery左側(cè)導(dǎo)航欄和頁面選中效果
- JQuery 浮動(dòng)導(dǎo)航欄實(shí)現(xiàn)代碼
- 用jquery的方法制作一個(gè)簡(jiǎn)單的導(dǎo)航欄
- Jquery給當(dāng)前頁或者跳轉(zhuǎn)后頁面的導(dǎo)航欄添加選中后樣式的實(shí)例
- jquery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊后展開列表內(nèi)容的導(dǎo)航欄效果
- jquery+css實(shí)現(xiàn)側(cè)邊導(dǎo)航欄效果
- jQuery Mobile 導(dǎo)航欄代碼
- jQuery點(diǎn)擊導(dǎo)航欄選中更換樣式的實(shí)現(xiàn)代碼
- jquery實(shí)現(xiàn)垂直和水平菜單導(dǎo)航欄
- jQuery實(shí)現(xiàn)帶展開動(dòng)畫的導(dǎo)航欄效果
相關(guān)文章
利用jQuery+localStorage實(shí)現(xiàn)一個(gè)簡(jiǎn)易的計(jì)時(shí)器示例代碼
這篇文章主要給大家介紹了關(guān)于利用jQuery+localStorage實(shí)現(xiàn)一個(gè)簡(jiǎn)易的計(jì)時(shí)器的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-12-12超級(jí)有用的13個(gè)基于jQuery的內(nèi)容滾動(dòng)插件和教程
這篇文章與大家分享13個(gè)超級(jí)有用的 jQuery 內(nèi)容滾動(dòng)插件和教程。您可能經(jīng)常能看到一些網(wǎng)站上特色區(qū)域的內(nèi)容以滾動(dòng)方式變化,這是一種在有限的網(wǎng)頁空間內(nèi)展示更多內(nèi)容的良好方式,而且能吸引用戶注意力。2011-07-07jQuery拖動(dòng)div、移動(dòng)div、彈出層實(shí)現(xiàn)原理及示例
正如標(biāo)題所言的實(shí)現(xiàn)原理是使div的position為絕對(duì)定位absolute,然后控制其top與left值,需要的朋友可以參考下2014-04-04Jquery實(shí)現(xiàn)瀑布流布局(備有詳細(xì)注釋)
這篇文章主要介紹了Jquery實(shí)現(xiàn)瀑布流布局的方法,可實(shí)現(xiàn)圖片的動(dòng)態(tài)加載功能,且代碼備有詳細(xì)注釋便于理解,需要的朋友可以參考下2015-07-07jQuery文本框得到與失去焦點(diǎn)動(dòng)態(tài)改變樣式效果
這篇文章主要介紹了jQuery文本框得到與失去焦點(diǎn)動(dòng)態(tài)改變樣式效果,涉及jQuery針對(duì)頁面表單元素樣式的動(dòng)態(tài)操作技巧,需要的朋友可以參考下2016-09-09jQuery實(shí)現(xiàn)在HTML文檔加載完畢后自動(dòng)執(zhí)行某個(gè)事件的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)在HTML文檔加載完畢后自動(dòng)執(zhí)行某個(gè)事件的方法,結(jié)合實(shí)例形式分析了document的ready()事件自動(dòng)加載執(zhí)行事件的相關(guān)操作技巧,需要的朋友可以參考下2017-05-05Jquery和JS獲取ul中l(wèi)i標(biāo)簽的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狫query和JS獲取ul中l(wèi)i標(biāo)簽的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06jQuery實(shí)現(xiàn)的類似淘寶網(wǎng)站搜索框樣式代碼分享
這篇文章主要介紹了類似淘寶網(wǎng)站搜索框樣式實(shí)現(xiàn)代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08JQuery Ajax執(zhí)行跨域請(qǐng)求數(shù)據(jù)的解決方案
今天小編就為大家分享一篇關(guān)于JQuery Ajax執(zhí)行跨域請(qǐng)求數(shù)據(jù)的解決方案,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12