var r = ‘#‘+ Math.random().toString(16).substr(-6);
Math.random().toString(16) 随机生成一个随机数,然后转为16进制字符串,截取后6位,now 就是随机颜色的后6位了。
JS一行代码,生成一个随机颜色,简单粗暴。
原文:https://www.cnblogs.com/hill-foryou/p/8954452.html