This article describes the method of implementing simple random lottery by js. Share it for your reference. The specific implementation method is as follows:
The code copy is as follows:
<html>
<title>js random lottery 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,f,g,h,i,j,k"
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()',100);
}
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" >Please 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>
I hope this article will be helpful to everyone's JavaScript programming.