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刪除。