当前位置:首页 > Web开发 > 正文

Math.floor取整color = color.length == 1?‘0‘+color:color;rgb.pu

2024-03-31 Web开发

function getRandomColor(){ let rgb = []; for(let i=0;i<3;++i){ let color = Math.floor(Math.random()*256).toString(16); //Math.random()*256是生成0-256之间的随机小数,,Math.floor取整 color = color.length == 1?‘0‘+color:color; rgb.push(color); } return ‘#‘ + rgb.join(‘‘); }

  

一个生成随机颜色的js函数

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30557.html