<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
background-color: #39c5bb;
margin: 50px;
padding: 20px;
border-radius: 10px;
}
</style>
</head>
<body>
<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>
<div id="div4">4</div>
<div id="div5">5</div>
<script language="JavaScript">
divcolor();
function divcolor(){
let divid =Math.floor(Math.random()*5+1);
let a =Math.floor(Math.random()*255);
let b =Math.floor(Math.random()*255);
let c =Math.floor(Math.random()*255);
document.getElementById("div"+divid).style.backgroundColor="rgb("+a+","+b+","+c+")";
setTimeout(divcolor,10);
}
</script>
</body>
</html>
结果图(颜色纯随机)
嗯