求随机颜色,至少用三种方法?
<script>
function getRandomColor (){
var r=parseInt(Math.random()*256).toString();
var g=parseInt(Math.random()*256).toString();
var b=parseInt(Math.random()*256).toString();
console.log("rgba(" +r+","+g+","+b+","+1+")");
}
getRandomColor();
</script>
<script>
function getRandomColor (){
var color="#";
for(var i=0;i<3;i++){
var str=parseInt(Math.random()*256);
if(str<16){
str = "0" + str.toString(16);
}else{
str = str.toString(16);
}
color += str;
}
console.log(color);
}
getRandomColor();
</script>