js在前端的用途极为广泛,可以用来制作各种动效,各种的效果,js中的ajax让浏览器可以无刷新提交,极大地降低了服务器的负载,本次带来的是js中的随机颜色方块,可以实现五彩斑斓的颜色,大家快来体验一波吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js实现颜色变换_五彩斑斓</title> <style> *{margin:0;padding:0;font-family: Microsoft YaHei,serif;} li{list-style: none;} #box span{ float: left; width:80px; height: 40px; font-size:16px; font-weight: bold; color:#fff; text-align: center; line-height:40px; } </style> </head> <body> <div id="box"> </div> <script> var arr = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d",'e',"f"] var x = setInterval(function () { var aaa = Color(); box.innerHTML += "<span style='background: "+ aaa +";'>"+ aaa +"</span>" },100) document.onclick = function () { clearInterval(x) } function Color() { var str = "#" for(var i=0;i<6;i++){ str += arr[Math.floor(Math.random()*16)] // [0,15] } return str; } </script> </body> </html> |
7