发表于: 2016-06-07 17:28:03
1 1782
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<style type="text/css">
div{
width: 100px;
height: 100px;
display: inline-block;
margin: 0 50px;
background-color: #000;
}
</style>
<body>
<div id="a1"></div>
<div id="a2"></div>
<div id="a3"></div>
<div id="a4"></div>
<div id="a5"></div>
<div id="a6"></div>
<div id="a7"></div>
<div id="a8"></div>
<div id="a9"></div>
</body>
<script type="text/javascript">
var colors= ["#33b5e5","#0099cc","#aa66cc","#9933cc","#99cc00","#669900","#ffbb33","#ff8800","#ff4444","#cc0000"];
var a1 = document.getElementById('a1');
var a2 = document.getElementById('a2');
var a3 = document.getElementById('a3');
var a4 = document.getElementById('a4');
var a5 = document.getElementById('a5');
var a6 = document.getElementById('a6');
var a7 = document.getElementById('a7');
var a8 = document.getElementById('a8');
var a9 = document.getElementById('a9');
setInterval(
function(){
a1.style.background = colors[Math.floor(Math.random()*colors.length)];
a2.style.background = colors[Math.floor(Math.random()*colors.length)];
a3.style.background = colors[Math.floor(Math.random()*colors.length)];
a4.style.background = colors[Math.floor(Math.random()*colors.length)];
a5.style.background = colors[Math.floor(Math.random()*colors.length)];
a6.style.background = colors[Math.floor(Math.random()*colors.length)];
a7.style.background = colors[Math.floor(Math.random()*colors.length)];
a8.style.background = colors[Math.floor(Math.random()*colors.length)];
a9.style.background = colors[Math.floor(Math.random()*colors.length)];
},1000
);
</script>
</html>
评论