<div class="container">
<ul>
<li>鼠标经过时改变背景色</li>
<li>鼠标经过时改变背景色</li>
<li>鼠标经过时改变背景色</li>
<li>鼠标经过时改变背景色</li>
</ul>
</div>
window.onload = function() {
var user_name = document.getElementById("user_name");
changeBgc();
}
function changeBgc() {
var lis = document.getElementsByTagName("li");
for (var i=0; i<lis.length; i++) {
lis[i].onmouseover = function() {
this.setAttribute("class", "current");
}
lis[i].onmouseout = function() {
this.setAttribute("class", "");
}
}
}
* {
padding:0px;
margin:0px;
}
.container {
width:960px;
margin:20px auto;
}
ul li {
padding:5px 0;
background-color:blue;
margin:8px 0;
color:#FFFFFF;
}
ul li.current {
background-color:red;
cursor:pointer;
}