2.模拟双色球抽奖


 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title>T67-模拟抽奖</title>
 6     <style type="text/css">
 7         *{
 8             padding:0;
 9             margin:0;
10         }
11         p{
12             margin-left: 300px;
13             margin-top:20px;
14             font-size: 22px;
15             60px;
16             height:30px;
17         }
18         button{
19             margin-left: 400px;
20             margin-top:60px;
21              50px;
22             height: 20px;
23         }
24     </style>
25     
26 </head>
27 <body>
28 <p id="p"></p>
29 <button onclick="playFun()" type="button">点击</button>
30 
31 
32 
33 <script type="text/javascript">
34    var playFun= function () {
35 
36        var randoms=[];
37        var flag=true;
38        for(var i=0;i<=5;i++){
39            flag=true;
40            var random= Math.floor(Math.random()*33+1);
41            console.log(random);
42            if(i>0){
43                for(var k=0;k<randoms.length;k++){
44                    if(randoms[k]==random){
45                        flag=false;
46                    }
47                }
48 
49 
50            }
51            if(!flag){
52                i--;
53                continue;
54 
55            }
56            randoms.push(random);
57 
58        }
59        randoms.sort(function (a, b) {
60            return a-b
61        });
62 
63        document.getElementById("p").innerHTML=randoms;
64 
65 
66 
67    }
68 
69 
70 
71 
72 </script>
73 
74 </body>
75 </html>
View Code



<!DOCTYPE html>

<html>
<head lang="en">
<meta charset="UTF-8">
<title>T67-模拟抽奖</title>
<style type="text/css">
*{
padding:0;
margin:0;
}
p{
margin-left: 300px;
margin-top:20px;
font-size: 22px;
60px;
height:30px;
}
button{
margin-left: 400px;
margin-top:60px;
50px;
height: 20px;
}
</style>

</head>
<body>
<p id="p"></p>
<button onclick="playFun()" type="button">点击</button>



<script type="text/javascript">
var playFun= function () {

var randoms=[];
var flag=true;
for(var i=0;i<=5;i++){
flag=true;
var random= Math.floor(Math.random()*33+1);
console.log(random);
if(i>0){
for(var k=0;k<randoms.length;k++){
if(randoms[k]==random){
flag=false;
}
}


}
if(!flag){
i--;
continue;

}
randoms.push(random);

}
randoms.sort(function (a, b) {
return a-b
});

document.getElementById("p").innerHTML=randoms;



}




</script>

</body>
</html>
原文地址:https://www.cnblogs.com/mx2036/p/6667481.html