Js did made a lottery system
<meta charset="UTF-8">
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
<meta HTTP - equiv="X - UA - Compatible" content="ie=edge" & gt;
Random name & lt;/title>
<style>
# content {
width:100%;
height: 100%;
Background: # ffaa7f;
Margin: 100 px auto;
text-align: center;
position: relative;
Margin - top: 150 px;
The line - height: 350 px;
color: dodgerblue;
The font - size: 70 px;
}
# btn1 {
background: #ccc;
Width: 180 px;
Height: 80 px;
font-size: 30px;
Color: # f40;
Border - the radius: 12 px;
position: absolute;
Bottom: 30 px;
Left: 29%;
Margin - left: - 90 px;
}
# btn2 {
background: #ccc;
Width: 180 px;
Height: 80 px;
font-size: 30px;
Color: # f40;
Border - the radius: 12 px;
position: absolute;
Bottom: 30 px;
Right: 13%;
Margin - left: - 90 px;
}
# button - group {
position: relative;
Top: 15 px;
}
# BTN - sontent {
position: relative;
Bottom: 55 px;
}
</style>
<body>
<script>
Var arr=[' Zhang Wenxin ', 'CAI penang wei', 'Cheng Donghui', 'Chen Jihao', 'Chen', 'jc Chen', 'si-jia Chen', 'major dong', 'Duan Chunxiao', 'FuYongXiu', 'Gao Wen];
Var $btn1=document. GetElementById (" btn1 ");
Var $btn2=document. GetElementById (" btn2 ");
Var $content=document. GetElementById (" content ");
Var $span1=document. GetElementById (' span1 ');
var timer;//timer
Var testNum=true;
$btn1. Onclick=function () {
If (testNum) {
//the console. The log (1);
start();
$btn1. InnerHTML='you! ';
TestNum=false;
}
The else {
//the console. The log (0);
Stop ();
$btn1. InnerHTML='to';
TestNum=true;
}
}
$btn2. Onclick=function () {
Restart ();
}
The function start () {
//timer=setInt erval (function () {
//var num=random (1, arr. Length - 1);
//$span1. InnerHTML=arr (num);
//}, 10)
The timer=setInterval (function () {
Var num=random (0, arr. Length)
$span1. InnerHTML=arr (num)
}, 10)
}
The function the stop () {
//clearInterval () is used to stop the setinterval function
clearInterval(timer);
}
The function restart () {
$span1. InnerHTML='click start;
}
//random function
The function of random (a, b) {
Var randomNum=Math. Round (Math. The random () * (b - a)) + a;
//var test=Math. Round (math.h random () * (13-7)) + 7;
Return randomNum;
}
</script>