js随机生成颜色

5,361 阅读1分钟

随机生成rbg值

function rgb(){
    let r = Math.floor(Math.random()*256);
	let g = Math.floor(Math.random()*256);
	let b = Math.floor(Math.random()*256);
	let rgb = 'rgb('+r+','+g+','+b+')';
	return rgb;
}

随机生成16进制颜色

function color16(){
   let r = Math.floor(Math.random()*256);
   let g = Math.floor(Math.random()*256);
   let b = Math.floor(Math.random()*256);
   let color = '#'+r.toString(16)+g.toString(16)+b.toString(16);
   return color;
}