zoukankan      html  css  js  c++  java
  • Js-随机抽奖小demo

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title></title>
      <style>
        .box{
           800px;
          margin: 200px auto;
          text-align: center;
        }
        .box h2{
          font-size: 55px;
          font-weight: 800;
        }
        .box input{
          outline: none;
          border: none;
          background: blue;
          color: white;
           100px;
          height: 50px;
          font-size: 15px;
          font-weight: 600;
        }
      </style>
    </head>
    <body>
      <div class="box">
        <h2 id="res">请点击下面的按钮,开始抽奖!</h2>
        <input type="button" value="点击开始" id="btn">
      </div>
      
      <script>
       var btn=  document.getElementById("btn");
       var res=  document.getElementById("res");
        var student=["麻子","小明","小王","小胡","小虎","狗子","多银币","贡子哥","刘青松"]
        var flag=true;
        var timer=null;
        btn.onclick=function(){
          if(flag){
            timer= setInterval(function(){
             var index= getRandom(student.length-1,0) ;
             res.innerHTML=student[index]; 
            },10);
            btn.value="点击结束";
            flag=false;
          }else{
            clearInterval(timer);
            btn.value="点击开始";
            flag=true;
          }
          
        }
        function getRandom(max,min){
         return Math.round(Math.random()*(max-min)+min);
        }
      </script>
    </body>
    </html>
    

      随机抽名字

  • 相关阅读:
    【HDU3681】Prison Break-状态压缩DP+BFS+二分答案
    【BashuOJ3520】警察局长-最短路树+树上背包+概率DP
    【POJ1201】Intervals-差分约束系统+单源最长路
    【BashuOJ2041】最大矩形-矩阵型DP
    【BashuOJ2041】最大矩形-矩阵型DP
    deleted
    deleted
    deleted
    deleted
    deleted
  • 原文地址:https://www.cnblogs.com/yxkNotes/p/14977635.html
Copyright © 2011-2022 走看看