js随机数生成颜色
html、css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<div id="box">
<div id="subbox"></div>
</div>
</body>
</html>
js
changeColor(box);
function changeColor(obj) {
var a = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
var c = Math.floor(Math.random() * 255);
obj.style.background = "rgb(" + a + "," + b + "," + c + ")";
return obj;
}