Voyons l'effet en premier
Le code est le suivant
<! Doctype html> <html> <éadf> <meta charset = "utf-8"> <tight> random tag cloud </ title> <style type = "text / css"> * {margin: 0; rembourrage: 0} a {text-décoration: aucun} #wrap {width: 400px; marge: auto} </ style> <script type = "text / javascript"> window.onload = function () {var obox = document.getElementById ("wrap"); var obj = obox.getElementsByTagName ("a"); // Fonction de méthode aléatoire rand (num) {return parseInt (math.random () * num + 1); } // Fonction de valeur de couleur aléatoire RandomColor () {var str = math.ceil (math.random () * 16777215) .toString (16); if (str.length <6) {str = "0" + str; } return str; } // boucle pour (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 = "#" + randomcolor (); } obj [i] .onMouseout = function () {this.style.background = "Aucun"; } } } </script></head><body> <div id="wrap"> <a href="#">web standard learning</a> <a href="#">css</a> <a href="#">javascript</a> <a href="#">html5</a> <a href="#">canvas</a> <a href = "#"> Vidéo </a> <a href = "#"> Audio </a> <a href = "#"> jQuery </a> <a href = "#"> jQuery </a> <a href = "#"> jQueryMobile </a> <a href = "#"> Flash </a> <a href = "" " href = "#"> chrome </a> <a href = "#"> opéra </a> <a href = "#"> ie9 </a> <a href = "#"> css3.0 </a> <a href = "#"> Andriod </a> <a href = "#"> Apple </a> <a href = "" " href = "#"> href = "#"> google </a> <a href = "#"> Jobs </a> </div> </ body> </html>Cet algorithme est relativement simple (je peux comprendre orz ...), mais il implémente essentiellement les exigences
Ce qui précède est l'intégralité du contenu de cet article. Pour plus d'informations sur JavaScript, vous pouvez consulter: "JavaScript Reference Tutorial" et "JavaScript Code Style Guide". J'espère également que tout le monde soutiendra davantage Wulin.com.