JS初学之-js的a:hover

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
.active{background:yellow;}
div{width:200px;height:200px;background:#F00;display:none}
</style>
<script>
window.onload=function(){
var aBtn=document.getElementsByTagName('input');
var aDiv=document.getElementsByTagName('div');

for(var i=0;i<aBtn.length;i++){
aBtn[i].index=i;
aBtn[i].onmouseover=function(){
for(var i=0;i<aBtn.length;i++){
aBtn[i].className='';
aDiv[i].style.display='';
};
this.className='active';
aDiv[this.index].style.display='block';
};
};

};
</script>
</head>

<body>
<input type="button" value="按钮1" />
<input type="button" value="按钮2" />
<input type="button" value="按钮3" />
<input type="button" value="按钮4" />
<input type="button" value="按钮5" />
<div style="display:block">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</body>
</html>

上一篇:单源最短路径算法:迪杰斯特拉 (Dijkstra) 算法(一)


下一篇:Objective-C系列