<ul id="nav_list">
<li><a href="#" class="nav01" onclick="navChangeBg(0)">法國報價</a></li>
<li><a href="#" onclick="navChangeBg(1)">法國報價</a></li>
<li><a href="#" onclick="navChangeBg(2)">法國報價</a></li>
<li><a href="#" onclick="navChangeBg(3)">法國報價</a></li>
<li><a href="#" onclick="navChangeBg(4)">法國報價</a></li>
</ul>
css樣式:
ul,li {
list-style:none;
}
#nav_list {
background:#a00100;
height:30px;
line-height:30px;
}
#nav_list li {
float:left;
margin: 0 20px;
}
#nav_list a:link,#nav_list a:visited {
color:#fff;
font-size:14px;
font-weight:bold;
text-decoration:none;
height:30px;
float:left;
padding:0 5px;
}
#nav_list a:hover {
text-decoration:underline;
}
#nav_list .nav01:link,#nav_list .nav01:visited {
background:#fff;
color:#a00100;
}
js代碼:
function navChangeBg(num) {
var navId = document.getElementById("nav_list");
var navA = navId.getElementsByTagName("a");
for(var i=0;i<navA.length;i++) {
if(i == num) {
navA[i].className = "nav01";
} else {
navA[i].className = "";
}
}
}