As shown below;
Copy codeThe Code is 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 ("");
For (var I = 0; I <a. length; I ++)
{
A [I]. className = "";
}
Obj. className = "current ";
}
</Script>
<Style type = "text/css">
Body {
Font-size: 17px;
}
. Current {
Background: red;
}
# Container ul
{
List-style-type: none;
}
# Container ul li
{
Float: left;
Margin-right: 3px;
}
# Container ul li {
Text-decoration: none;
Color: #000;
}
</Style>
</Head>
<Body>
<Div id = "container">
<Ul id = "Menu">
<Li> <a href = "javascript:" onclick = "change_bg (this)" class = "current"> 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>