Js lottery to achieve random lottery code effect

  • 2020-03-30 00:42:13
  • OfStack

Random, simple code.

 
<html> 
<title> Random draw program </title> 
<head><meta http-equiv=Content-Type content="text/html; charset=gb2312"> 
</head> 
<body> 
<script type="text/javascript"> 
var alldata = "a,b,c,d,e" 
var alldataarr = alldata.split(","); 
var num = alldataarr.length-1 ; 
var timer 
function change() 
{ 
document.getElementById("oknum").innerHTML = alldataarr[GetRnd(0,num)]; 
} 
function start(){ 
clearInterval(timer); 
timer = setInterval('change()',10); 
} 
function ok(){ 
clearInterval(timer); 
document.getElementById("showresult").value=document.getElementById("oknum").innerText; 
} 
function GetRnd(min,max){ 
return parseInt(Math.random()*(max-min+1)); 
} 
</script> 
<center> 
<div id="oknum" name="oknum" > Click start </div> 
<button onclick="start()" accesskey="s"> start </button> 
<button onclick="ok()" accesskey="o"> stop </button> 
 Your choice is:  
<input type="text" id="showresult" value=""> 
</center> 
</body> 
</html>


Related articles: