Vamos ver o efeito primeiro
O código é o seguinte
<! Doctype html> <html> <head> <meta charset = "utf-8"> <title> Tag Random Cloud </title> <style type = "text/css">*{margem: 0; preenchimento: 0} a {decoração de texto: nenhum} #wrap {width: 400px; margem: auto} </style> <script type = "text/javascript"> window.onload = function () {var obox = document.getElementById ("wrap"); var obj = obox.getElementsByTagName ("A"); // Função de método aleatório rand (num) {return parseint (math.random ()*num+1); } // Função de valor de cor aleatória RandomColor () {var str = Math.ceil (Math.random ()*16777215) .ToString (16); if (str.Length <6) {str = "0"+str; } retornar str; } // loop for (len = obj.length, i = len; i-;) {obj [i] .className = "color"+rand (5); obj [i] .style.zindex = rand (5); obj [i] .style.fontsize = rand (12) +12+ "px"; // obj [i] .style.background = "#"+randomcolor (); obj [i] .style.color = "#"+randomcolor (); obj [i] .onMouseOver = function () {this.style.background = "#"+aleatomcolor (); } obj [i] .onMouseOut = function () {this.style.background = "nenhum"; }}} </script> </adhead> <body> <div id id = "wrap"> <a href = "#"> aprendizagem padrão da web </a> href = "#"> vídeo </a> <a href = "#"> áudio </a> <a href = "#"> jQuery </a> href = "#"> Chrome </a> <a href = "#"> opera </a> <a href = "#"> ie9 </a> <a href = "#"> css3.0 </a> <a href = "#"> andriod </a> <a href = "# href = "#"> href = "#"> google </a>Esse algoritmo é relativamente simples (eu posso entender Orz ...), mas basicamente implementa os requisitos
O acima é o conteúdo inteiro deste artigo. Para obter mais informações sobre JavaScript, você pode conferir: "Javascript Reference Tutorial" e "JavaScript Code Style Guide". Eu também espero que todos apoiem mais wulin.com.