我正在研究一个小项目,该项目从所有可能的颜色中为该圆圈指定一个随机颜色。随机彩色圆圈
我试图通过给每个RGB值分配一个随机数来实现这一点。但是,它似乎没有这样工作。我也尝试setAttribute()方式来指定它,但也没有运气。请看看:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Beginning JavaScript</title>
<style>
#circle{
margin:auto;
border:1px solid black;
border-radius: 50%;
background-color:rgb(0,0,0);
height:200px;
width:200px;
}
</style>
</head>
<body>
<div id="circle"></div>
<script>
var circle = document.getElementById('circle');
var value1 = Math.floor(Math.random() * 256);
var value2 = Math.floor(Math.random() * 256);
var value3 = Math.floor(Math.random() * 256);
circle.style.backgroundColor = "rgb(value1,value2,value3)"
'circle.style.backgroundColor = “RGB(” +值1 +”, “+值2 +” ,“+ value3 +”)“' – rgthree
[为什么不使用backgroundColor = rgb(a,b,c)?](http://stackoverflow.com/questions/14323082/why-doesnt-backgroundcolor-rgba -bc-work) – FrankerZ