方案一:
var num16 = "ffffff";
var num10 = parseInt(num16,16);//16进制转10进制
console.log(num10) // 16777215
var colorNum = Math.round(Math.random()*num10).toString(16);
colorNum = ("000000"+colorNum).slice(-6)
console.log("#"+colorNum)
方案二:
function getRandomColor(){ return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6); // >>0取整 +0.5四舍五入 }