颜色的赋值方式:
1.通过英文名
2.通过rgb三原色调配比例,赋值大于0,小于255;
3.通过16进制来匹配(一般不用)
透明度opacity
1为不透明,0为完全透明;
随机色
<body>
<div class="box"></div>
<div style="width: 100px; height: 100px; background: red;"></div>
<script type="text/javascript">
var box = document.getElementsByClassName("box")[0]; //获取元素
function c(){
return Math.floor(Math.random()*255);//通过随机数获取到一个数值
}
//通过使用 rgb三原色 来完成随机颜色的赋值
box.style.backgroundColor = 'rgb(' + c() + ',' + c() + ','+ c()+ ')';
</script>
</body>