代码:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ul>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
<li>随机变色</li>
</ul>
<script>
let li = document.getElementsByTagName('li')[0]
let ul = li.parentNode
let ulson = ul.children
let i=0
function sj(){
return Math.floor(Math.random()*256)
}
setInterval(o=>{
ulson[i].style.backgroundColor=`rgb(${sj()},${sj()},${sj()})`
i++
if(i==ulson.length){
i=0
}
},1000)
</script>
</body>
</html>
效果图: