87,988
社区成员




<script type="text/javascript">
var usernameEle = document.getElementById("list1");
var childs = usernameEle.childNodes;
for (var i =1 ; i < childs.length; i+=2) {
childs[i].conunt=2;
};
function change(x){
for (var i =1 ; i < childs.length; i+=2) {
childs[i].style.backgroundColor="white";
childs[i].conunt=2;
};
if(x.conunt%2==0){
x.style.backgroundColor="red";
}
else{
x.style.backgroundColor="white";
}
x.conunt++;
}
</script>
记得把这段JS放在ul标签后面,不能放在head标签里面了,否则会失效。(ps:我不是什么大神,还是一个实习生,也才学JS1个星期,多做做就熟悉了。记得结贴给分。)
<!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" />
<style type="text/css">
.gzztxx{
width:186px;
height:35px;
background:url(img/gzztxx_line.png) no-repeat bottom;
padding:0px 7px 0px 7px;
}
.gzztxx
.gzztxx p{
font:12px"宋体";
color:#333;
line-height:35px;
float:left;
}
.gzztxx ul{
float:right;
margin-top:8px;
}
.gzztxx .gzztxx_zhuangtai li{
float:left;
padding-left:12px;
}
</style>
<title>无标题文档</title>
<script type="text/javascript">
var i=1;
function change(x){
if(i%2==0){
x.style.backgroundColor="red";
}
else{
x.style.backgroundColor="white";
}
i++;
}
</script>
</head>
<body>
<div class="gzztxx" onclick="change(this)">
<p>粤HTZ040</p>
<ul class="gzztxx_zhuangtai">
<li><img src="img/icon_fire.png" alt="火"/></li>
<li><img src="img/icon_close.png" / alt="门"></li>
<li><img src="img/icon_phone.png" alt="电话" /></li>
<li><img src="img/icon_sp.png" / alt="视频"></li>
</ul>
</div>
</body>
</html>