• 随机点名系统


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>随机点名</title>
    <style type="text/css">
    td{
    text-align: center;
    }
    </style>
    </head>
    <body>
    <table width="760" border="1" height="460" align="center">
    <h1 align="center">随机点名系统</h1>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table>
    <div align="center">
    <br/>
    <br/>
    <input type="button" value="随机抽取" onclick="selectRandom();"/>
    <input type="button" value="打乱顺序" onclick="Upsetorder();"/>
    <br/>
    <br/>
    <input type="button" value="快速抽取" onclick="Quickextr();"/>
    <input type="button" value="停止抽取" onclick="Stopextr();"/>
    </div>
    <script type="text/javascript">
    var classMate = ["周远","刘婷","戴安娜","范泛","向向",
    "天天","花花","小平","小云","小鑫",
    "赵赵","小妹","苏微","李子","曾小夏",
    "李佳加","钟文","张强","袁豪","余成",
    "付金","彭康","邓佳","曹曹","刘东",
    "桂话","彭斌","周华","小增","蒋大爷"];
    //定义一个变量存随机数组
    var indexArr;
    //打乱顺序
    function Upsetorder(){
    alert(1);
    //初始化数组
    indexArr = [];
    //获取新的随机数
    var rd = parseInt(Math.random()*classMate.length);
    while(true){
    do{
    var falg = true;
    //循环获得每一个下标
    for (var i = 0 ; i <classMate.length ; i++) {
    //判断是否已存在这个下标,是否为重复之后 跳出
    if(indexArr[i] == rd){
    falg = false;
    break;
    }
    }
    //判断是否添加
    if(falg){
    indexArr.push(rd);
    }
    rd = parseInt(Math.random()*classMate.length);
    }while (falg);
    if(indexArr.length == classMate.length){
    break;
    }
    }
    }
    //随机抽取
    function selectRandom(){
    var allTd = document.getElementsByTagName("td");
    for (var i = 0; i < classMate.length; i++) {
    allTd[i].innerHTML = classMate[indexArr[i]];
    allTd[i].style.color = "#ff6633";
    allTd[i].style.background = "#ff6633";
    allTd[i].onclick = function (){
    this.style.background = "white";
    }
    }
    }
    //快速抽取
    var interId;
    var count = 0;
    //保存已被选出的人
    var myChecked = [];
    var allTd = document.getElementsByTagName("td");
    function Quickextr(){
    if(interId){
    return;
    }
    //把所有的td还原为最初
    interId = setInterval(function(){
    for (var i = 0; i < classMate.length; i++) {
    allTd[i].style.color = "#ff6633";
    allTd[i].style.background = "#ff6633";
    }
    for (var i = 0; i < myChecked.length; i++) {
    allTd[myChecked[i]].style.color = "#ff6633";
    allTd[myChecked[i]].style.background = "white";
    }
    allTd[count%classMate.length].style.color = "white";
    allTd[count%classMate.length].style.background = "white";
    count++;
    },1);
    }
    //停止抽取
    function Stopextr(){
    clearInterval(interId);
    interId = undefined;
    var checkIds = count%classMate.length==0?classMate.length-1:(count%classMate.length)-1;
    allTd[checkIds].style.color = "#ff6633";
    myChecked.push(checkIds);
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    greenDao 学习之坑 "java-gen" 目录下的类不能引用
    fastboot 刷system.img 提示 sending 'system' (*KB)... FAILED (remote: data too large)
    AndroidStudio导入第三方开源库 --文件夹源码
    git 克隆项目 与 分支简单操作
    Jquery当选中后费用或什么信息会自增长
    Jquery中各种标签的含义集合
    Jquery判断是否重复(连接到后台数据库进行比较)
    Jquery按空格键选中复选框或单选框
    JS(JQuery)操作Array的相关方法
    前端知识点-人资相关知识点
  • 原文地址:https://www.cnblogs.com/835328162qq/p/7682074.html
Copyright © 2020-2023  润新知