首页 > 代码库 > js实例2表框

js实例2表框

<style type="text/css">
#caidan{
width:500px; height:35px; border:1px solid #60F;

}

.xiang{
width:100px;
height:35px;
text-align:center;
line-height:35px;
vertical-align:middle;
float:left;
}

</style>
</head>

<body>

<div id="caidan">
<div class="xiang" onm ouseover="huan(this)" >首页</div>
<div class="xiang" onm ouseover="huan(this)" >产品中心</div>
<div class="xiang" onm ouseover="huan(this)" >服务中心</div>
<div class="xiang" onm ouseover="huan(this)" >联系我们</div>
</div>


</body>
<script type="text/javascript">
function huan(a)
{
//将所有的项恢复原样式
var d = document.getElementsByClassName("xiang");
for(var i=0;i<d.length;i++)
{
d[i].style.backgroundColor="white";
d[i].style.color = "black";
}

//换该元素的样式
a.style.backgroundColor = "red";
a.style.color = "white";
}
/*function huifu(a)
{
a.style.backgroundColor = "white";
a.style.color = "black";
}*/
</script>

js实例2表框