var color = '#'+ Math.random().toString(16).substr(-6);
document.body.style.backgroundColor = color;
这样 你每次刷新,就会呈现出不同的颜色。
- Dont believe, just try.
Math.random().toString(16) 随机生成一个随机数,然后转为16进制字符串,截取后6位,now 就是随机颜色的后6位了。
var color = '#'+ Math.random().toString(16).substr(-6);
document.body.style.backgroundColor = color;
这样 你每次刷新,就会呈现出不同的颜色。
Math.random().toString(16) 随机生成一个随机数,然后转为16进制字符串,截取后6位,now 就是随机颜色的后6位了。
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。