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

  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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值