function randomColor() {  
var arrHex = ["0","1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d","e","f"],
strHex = "#",
index;
for(var i = 0; i < 6; i++) {
index = Math.round(Math.random() * 15);
strHex += arrHex[index];
}
return strHex;
}

使用:将上面方法放到js当中,然后调用下面的方法,即可获取随机生成的颜色

console.log(randomColor());