<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>随机颜色</title>
</head>
<body>
<script>
function getRandomColor(){
// var r=(Math.random()*255).toFixed(0);
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+","+Math.random().toFixed(2)+")");
}
getRandomColor();
</script>
</body>
</html>
运行结果
来源:CSDN
作者:你知道歌谣吗?
链接:https://blog.csdn.net/weixin_43392489/article/details/104043318