使用Math.random()*256设置数字在0-256之间随机出现;
使用Math.floor设置随机出现的数字为整数;
设置 一个盒子,
使用Dom操作提取div;
使用JS设置样式,拼接字符串来表示rgb颜色
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="div"></div>
<script type="text/javascript">
r=Math.floor(Math.random()*256);
g=Math.floor(Math.random()*256);
b=Math.floor(Math.random()*256);
var div=document.getElementById('div');
div.style.background='rgb('+r+','+g+','+b+')';
div.style.width=200+'px';
div.style.height=200+'px';
</script>
</body>
</html>