<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
margin: 50px auto;
background-color: #bab5b9;
width: 240px;
height: 360px;
}
li{
width: 60px;
height: 60px;
margin-left: 15px;
background-color: #666666;
list-style: none;
float: left;
margin-top: 15px;
}
div{
width: 200px;
height: 160px;
background-color: #bb5655;
margin: 0 auto;
}
.g{
background-color: #00ff90;
}
</style>
<script>
window.onload=function () {
var ali=document.getElementsByTagName("li");
var adiv=document.getElementById("a");
var i=0;
for(i<ali.length;i++){
ali[i].onclick=function () {
for(i=0;i<ali.length;i++){
ali[i].className="";
}
this.className="g";
}
}
}
</script>
</head>
<body>
<ul>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
<li>cakak</li>
</ul>
<div id="a"></div>
</body>
</html>
相关分类