您好,登錄后才能下訂單哦!
廢話不多說了,直接給大家貼js實現鼠標點擊導航欄變色代碼,具體代碼如下所示:
<!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=utf-8" /> <title>JAVASCRIPT之導航欄鼠標點擊變色特效</title> <style type="text/css"> body { font-size:12px; font-family: Arial, Helvetica, sans-serif; } .ts_seled { color: #F00; } .ts_sel { color:#666; } </style> <script language="javascript"> window.onload = initLinkStyle; function initLinkStyle() { if(document.getElementsByName('myset')){ var arrLink = document.getElementsByName('myset'); for(i = 0; i < arrLink.length; i++) { var link = arrLink[i]; link.className='ts_sel'; link.onclick = clickNav; } } } /** * 執行點擊事件 * @param {Object} event 鼠標事件 */ function clickNav(event) { var target = event.currentTarget; //上次選擇的a的樣式 if(document.getElementsByName('myset')){ var arrLink = document.getElementsByName('myset'); for(i = 0; i < arrLink.length; i++) { var link = arrLink[i]; if(link.className == 'ts_seled') { link.className = 'ts_sel'; } } } target.className = 'ts_seled'; return false;//阻止瀏覽器默認事件 } </script> </head> <body> <ul> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" name="myset">首頁</a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" name="myset">聯系我們</a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" name="myset">幫助</a> </li> </ul> </body> </html>
以上所述是小編給大家介紹的JavaScript實現鼠標點擊導航欄變色特效,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。