Skip to content

获取随机颜色

方法1

js
function randomColor() {
    var r = Math.floor(Math.random() * 256);
    var g = Math.floor(Math.random() * 256);
    var b = Math.floor(Math.random() * 256);

    return `rgb(${r}, ${g}, ${b})`;
}

方法2

js

function randomColor() {
    
    return "#" + Math.random().toString(16).padStart(6, "0") 
}