Dieser Artikel beschreibt die Methode zur Implementierung einer einfachen zufälligen Lotterie durch JS. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
Die Codekopie lautet wie folgt:
<html>
<titels> JS Random Lottery Program </title>
<Head> <meta http-äquiv = content-type content = "text/html; charset = gb2312">
</head>
<body>
<script type = "text/javaScript">
var alldata = "a, b, c, d, e, f, g, h, i, j, k"
var alldataar = alldata.Split (",");
var num = alldataarr.length-1;
var Timer
Funktionsänderung ()
{
document.GetElementById ("oktum"). Innerhtml = alldatArarr [getrnd (0, num)];
}
Funktion start () {
ClearInterval (Timer);
Timer = setInterval ('change ()', 100);
}
Funktion OK () {
ClearInterval (Timer);
document.getElementById ("showResult"). value = document.getElementById ("oklumum"). InnerText;
}
Funktion getrnd (min, max) {
return parseInt (math.random ()*(max-min+1));
}
</script>
<Center>
<div id = "oktum" name = "oktum"> klicken Sie auf Start </div> klicken
<button onclick = "start ()" AccessKey = "S"> start </button>
<button onclick = "OK ()" AccessKey = "O"> Stop </button>
Ihre Wahl ist:
<Eingabe type = "text" id = "showResult" value = "">
</center>
</body>
</html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.