Javascript implements a simple random lottery, and js implements a lucky draw.
This example describes how to implement a simple random lottery in JavaScript. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code 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"> 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 help you design javascript programs.