<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>myTest</title>
<style>
body{
margin: 0;
padding: 0;
}
ul{ width: 400px;
height: 340px;
list-style: none;
position: relative;
}
li{
width: 100px;
height: 40px;
cursor: pointer;
float: left;
}
li:nth-child(1){
background: blue;
}
li:nth-child(2){
background: green;
}
li:nth-child(3){
background: yellow;
}
li:nth-child(4){
background: red;
}
div{
width: 400px;
height: 300px;
display: none;
position: absolute;
left: 40px;
top: 40px;
}
li:nth-child(1) div{
background: blue;
display: block;
}
li:nth-child(2) div{
background: green;
}
li:nth-child(3) div{
background: yellow;
}
li:nth-child(4) div{
background: red;
}
</style>
<script>
window.onload=function(){
var oLi = document.getElementsByTagName('li');
var oDiv = document.getElementsByTagName('div');
for (var i = 0; i < oLi.length; i++) {
oLi[i].onclick = function(){
oDiv[i].style.display = "block";
}
}
}
</script>
</head>
<body>
<ul>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
</ul>
</body>
</html>
相关分类