<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> div { width: 300px; height: 200px; box-shadow: 0 0 5px lightblue; font-size: 24px; } </style> </head> <body> <div>this is div</div> <script> var div = document.querySelector('div'); // the console.log (div); // wrapper function function the getColor () { // # Number var STR = '#' ; // 0 E-array var ARR = [ '0', '. 1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e ',' F ' ]; // 6 cycles for ( var I = 0; I <6; I ++ ) { // random 16-bit numbers in this letter var NUM = the parseInt (Math.random () * 16 ); // add to each STR ARR [NUM]; STR + =arr [NUM]; } return str; } // console.log (getColor ()); // document registration click event, click div random color document.onclick = function () { div.style.backgroundColor = getColor (); div.style.color = the getColor (); } </ Script> </ body> </ HTML>
A random hexadecimal color
Guess you like
Origin www.cnblogs.com/sandraryan/p/11610085.html
Recommended
Ranking