This article is mainly on the JS navigation bar Click event Background to change the sample code is introduced, the need for friends can come to the reference, I hope to help you.
as shown below; Code as follows: <! 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> Untitled document </title> <script type=" Text/javascript "> Function change_bg (obj) { var A=document.getelementbyid ("menu"). getElementsByTagName ("a"); for (var i=0;i<a.length;i++) { a[i].classname= ""; } Obj.classname= "current"; } </script> <style type= "Text/css" > body{ font-size:17px; }. current{ &NBSP ; background:red; } #container ul { List-style-type:none;} #container ul li { float:left; MARGIN-RIGHT:3PX; #container ul li a{text-decoration:none color: #000 } </style> </head> <body> <div id= "container" > <ul id= "menu" > <li><a href= "javascript:" onclick= " CHANGE_BG (This) "class=" >Menu1</a></li> <li><a href= "javascript: onclick=" Change_ BG (This) ">Menu2</a></li> <li><a href=" javascript: onclick= "CHANGE_BG (This)" >Menu3< /a></li> <li><a href= "javascript:" onclick= "CHANGE_BG (This)" >Menu4</a></li> < Li><a href= "javascript:" onclick= "CHANGE_BG (This)" >Menu5</a></li> </ul> </div> </body> </html>