Il s'agit en fait d'un exercice pour les nombres aléatoires JS. Écrivez d'abord les noms de chacun dans un tableau à l'avance, puis laissez les valeurs du tableau s'afficher rapidement dans la zone. Lorsque vous appuyez sur Stop, le défilement s'arrête pour obtenir un effet aléatoire.
<! Doctype html> <html> <éadf> <meta charset = "utf-8" /> <tapie> Nom aléatoire écrit par JS-QIONGTAI Blog </Title> <Script Type = "Text / Javascrip action (str) {var s = document.getElementById ("bt"). valeur; if (s == "start") {Isrun = true; run (); document.getElementyid ("bt"). value = "end";} else {isrun = false; document.getElementyid ("bt"). Math.floor (math.random () * a.Length + 1) -1; document.getElementByid ("show"). InnerHtml = a [i]; if (isrun == false) {var b = true; for (var j dans a2) {if (a2 [j] == i) {b = false;}} if (b) { a2 [a2.Length] = i; return;}} setTimeout ("run ()", 10);} </cript> </ head> <body> <div style = "text-align: Center; margin-top: 100px; width: 100%;"> <div id = "show" style = "margin: auto; font-size: 50px; width: 100px; height: 50px; background: #ffeeff"> </ div> <div style = "margin-top: 20px;"> <input id = "bt" type = "bouton" onClick = "Action ()" value = "start" /> </v> </v> </gody> </html>