[Java学习] JavaScript实现的随机色标签云

时间:2021-11-17 14:51:32
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. <style type="text/css">
  7. http://www.nvzi91.cn/buyunbuyu/30049.html
  8. *{
  9. margin:0;
  10. padding:0
  11. }
  12. a{
  13. text-decoration:none
  14. }
  15. http://www.nvzi91.cn/fujianyan/30050.html
  16. #wrap{
  17. width:400px;
  18. margin:auto
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id="wrap">
  24. <a href="#">web标准学习</a>
  25. http://www.nvzi91.cn/waiyinyan/30051.html
  26. <a href="#">css</a>
  27. <a href="#">javascript</a>
  28. <a href="#">html5</a>
  29. <a href="#">canvas</a>
  30. <a href="#">video</a>
  31. <a href="#">audio</a>
  32. <a href="#">jQuery</a>
  33. <a href="#">jQuerymobile</a>
  34. <a href="#">flash</a>
  35. <a href="#">firefox</a>
  36. http://www.nvzi91.cn/yindaoyan/30052.html
  37. <a href="#">chrome</a>
  38. <a href="#">opera</a>
  39. <a href="#">IE9</a>
  40. <a href="#">css3.0</a>
  41. <a href="#">andriod</a>
  42. <a href="#">apple</a>
  43. <a href="#">google</a>
  44. <a href="#">jobs</a>
  45. http://www.nvzi91.cn/fujianyan/30053.html
  46. </div>
  47. <script type="text/javascript">
  48. //随机方法
  49. function rand(num)
  50. {
  51. return parseInt(Math.random()*num+1);
  52. }
  53. //随机颜色值
  54. function randomColor()
  55. www.nvzi91.cn
  56. {
  57. var str = Math.ceil((Math.random()*16777215)).toString(16); //把数字转换成16进制
  58. if(str.length < 6)
  59. {
  60. str = "0" + str;
  61. }
  62. return str;
  63. }
  64. //标签实现
  65. var aList = document.getElementById("wrap").getElementsByTagName("a");
  66. var i = 0;
  67. var len = aList.length;
  68. for(i;i<len;i++)
  69. {
  70. aList[i].className = "color"+rand(5); //生成随机类名
  71. aList[i].style.fontSize = rand(12)+12+"px"; //随机字号
  72. aList[i].style.color = "#"+randomColor();
  73. aList[i].onmouseover = function()
  74. {
  75. this.style.background = "#"+randomColor();
  76. }
  77. aList[i].onmouseout = function()
  78. {
  79. this.style.background = "";
  80. }
  81. }
  82. </script>
  83. </body>
  84. </html>