随机颜色方法记载:
方法1
// 生成6位 颜色rgb var getRandomColor = function(){ return '#' + (function(color){ return (color += '0123456789abcdef'[Math.floor(Math.random()*16)]) && (color.length == 6) ? color : arguments.callee(color); })(''); }
方法2
//生成 随机颜色 rgb的方法2 var getRandomColor1 = function(){ return (function(m,s,c){ return (c ? arguments.callee(m,s,c-1) : '#') + s[m.floor(m.random() * 16)] })(Math,'0123456789abcdef',5) }
方法3
//得到颜色值 方法3 16777215为十六进制0xffffff 取得方法:(alert(parseInt("0xffffff",16).toString(10));) //思想 随机产生0x000000 - 0xffffff 之间的一个十进制的数,然后在转换成十六进制 var getRandomColor3 = function(){ return '#'+Math.floor(Math.random()*16777215).toString(16); }
方法4
十六进制运算符例子: http://bbs.blueidea.com/thread-2943930-1-1.html
// 用十六进制 var getRandomColor4 = function(){ return '#'+(function(h){ return new Array(7-h.length).join("0")+h })((Math.random()*0x1000000<<0).toString(16)) }
document.write( "<div style='color:"+ getRandomColor5() +"'>222222</div>" );