日期:2014-05-17  浏览次数:20705 次

肯求各路神仙!!为什么鼠标滑过不变色呀~~~~~
html代码:

<!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" xml:lang="en">
<script src="myfun.js" type="text/javascript"></script>
<script tape="text/javascript">
window.onload=function(){
  var arr1=document.getElementById("ch_tab").getElementsByTagName("li");
  var arr2=document.getElementById("ch_tab_content");
arr3=getids(arr2,"tab_contents","div");

for(i=0;i<arr1.length;i++){
arr1[i].index=i;  
arr1[i].onmouseover=function(){
for(i=0;i<arr1.length;i++){
arr1[i].className="";
arr3[i].style.display="none";
}
  arr3[this.index].style.display="block";
this.className="active";

}
}
function getids(a,b,c){
var arr1=a.getElementsByTagName("div");
var arr=[];
for(i=0;i<arr1.length;i++){
if(arr1[i].className==b){
arr.push(arr1[i]); //把选出来的对象放在数组中
}
}
return arr;
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="./haibin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="tab_main">
<!-- tab标签 -->
<div id="ch_tab">
<ul class="ch_ul_tab">
<li class="active">aaaa</li>
<li>bbbb</li>
<li>cccc</li>
<li>dddd</li>
</ul>
</div>
<!-- tab的内容 -->
<div id="ch_tab_content">
<div class="tab_contents" >1111</div>
<div class="tab_contents" style="display:none;">2222</div>
<div class="tab_contents" style="display:none;">3333</div>
<div class="tab_contents" style="display:none;">4444</div>
</div>

</div>

</body>
</html>

CSS代码:

.tab_main{
width:600px;
height:400px;
border:1px solid gray;
}
/*tab标签*/
#ch_tab{


}
.ch_ul_tab{
width:560px;
height:26px;
border-bottom:1px solid gray;
}
.ch_ul_tab li{
width:70px;
height:25px;
float:left;
list-style:none;
margin-left:20px;
text-align:center;
background:green;
border-top:1px solid gray;
border-left:1px solid gray;
border-right:1px solid gray;

}
/*tab标签内容*/
#ch_tab_content{
clear:both;
width:600px;
height:364px;

}
.active{
background:yellow;
border-bottom:1px solid white;
}


------解决方案--------------------
.ch_ul_tab li.active{
background:yellow;
border-bottom:1px solid white;
}