随机颜色值

 1 function fn1(){
 2     return '#' + Math.floor( Math.random() * 0xffffff ).toString(16);
 3 }
 4 
 5 
 6 function fn2(){
 7     return '#' + ( Math.random() * 0xffffff<<0 ).toString(16);
 8 }
 9 
10 
11 function fn3(){
12     var r = Math.floor( Math.random() * 256 );
13     var g = Math.floor( Math.random() * 256 );    
14     var b = Math.floor( Math.random() * 256 );
15     return "rgb("+r+','+g+','+b+")";
16 }
17 
18 
19 function fn4(){
20     var color = "#";
21     for( var i = 0; i < 6; i++ ){
22         color += ( Math.random()*16 | 0 ).toString(16);
23     }
24     return color;
25 }
26 
27 
28 function fn5(){
29     var colorValue = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f";
30     var colorArray = colorValue.split(",");
31     var color = "#";
32     for( var i = 0; i < 6; i++ ){
33         color += colorArray[ Math.floor( Math.random() * 16 ) ];
34     }
35     return color;
36 }

 

posted @ 2021-11-26 16:03  璐瑶成鲲  阅读(61)  评论(0编辑  收藏  举报