js鼠标移入改变颜色,移除还原
<style type="text/css">.cd{width: 200px;height: 20px;border: solid 1px black;text-align: center;float: left;margin: 5px;}</style></head><body><div class="cd">菜单一</.
·
<style type="text/css">
.cd{
width: 200px;
height: 20px;
border: solid 1px black;
text-align: center;
float: left;
margin: 5px;
}
</style>
</head>
<body>
<div class="cd">
菜单一
</div>
<div class="cd">
菜单二
</div>
<div class="cd">
菜单三
</div>
<div class="cd">
菜单四
</div>
<div class="cd">
菜单五
</div>
</body>
<script type="text/javascript">
var yj=document.getElementsByClassName('cd');
for(var i=0;i<yj.length;i++){
yj[i].onmouseover=function(){
//console.log(i)
this.style.backgroundColor="red"
}
yj[i].onmouseout=function(){
this.style.backgroundColor="";
}
}
</script>
更多推荐
已为社区贡献1条内容
所有评论(0)