获取随机颜色js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取随机颜色js相关的知识,希望对你有一定的参考价值。

获取随机颜色
方法一:

function randomColor1() { 
    var rand = Math.floor(Math.random() * 0xFFFFFF).toString(16); 
    if(rand.length == 6){ 
        return rand; 
    }else{ 
        return randomColor(); 
    }
}

 

方法二:

function randomColor2(){
    return ‘#‘+(‘00000‘+(Math.random()*0x1000000<<0).toString(16)).slice(-6);
}

 

以上是关于获取随机颜色js的主要内容,如果未能解决你的问题,请参考以下文章