If you want to do the following, each time you refresh the page produces a color,
In fact, it's very simple, the fundamental core of the random color is the question of a six-digit, JavaScript random number that is created with the mechanism.
And this six-digit number is within each digit 0~f, so there is the following method:
1, the first is an HTML layout, p tag is used to put the current color, div background color is this color
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
2, followed by the core script:<script>//color string var colorstr= "";//the range of each character of the string var randomarr=[' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ' , ' C ', ' d ', ' e ', ' F '];//produces a six-bit string for (Var i=0;i<6;i++) {//15 is the range cap, 0 is the lower range, and two functions guarantee that the resulting random number is an integer colorstr+=randomarr[ Math.ceil (Math.random () * (15-0) +0)]; document.getElementById ("Colorstr"). innerhtml= "COLOR: #" +colorstr;document.getelementbyid ("Div1"). Style.backgroundcolor= "#" +colorstr;</script>
"JavaScript" produces random colors