【发布时间】:2015-02-27 19:53:45
【问题描述】:
我正在尝试将 div 'changebox' 设置为 rgb 的颜色,这是三个随机的结果。 rgb 正在改变,(我可以通过 document.writes 看出),但无论 rgb 是什么,div 都保持白色。请帮助将框更改为正确的 rgb 颜色。
<div id="changeBox" style="width: 150px; height: 150px; position: absolute; top: 10%; left: 10%; background-color: white; border: 4px solid black; color: black; font-family: 'Merriweather Sans', sans-serif;">
<script>
var randR = Math.floor(Math.random() * 255) + 1;
document.write(randR+", ");
var randG = Math.floor(Math.random() * 255) + 1;
document.write(randG+", ");
var randB = Math.floor(Math.random() * 255) + 1;
document.write(randB);
document.getElementById('changeBox').style = "background-color: rgb(" + randR + ", " + randG + ", " + randB + ");";
</script>
</div>
【问题讨论】:
标签: javascript css variables