zoukankan      html  css  js  c++  java
  • 前端学习笔记之随机点名

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>随机点名</title>
    </head>

    <body>
        <h1 class="name" id="names">点名</h1>
        <input type="button" value="开始" id=start_btn>
        <input type="button" value="结束" id=stop_btn disabled>
        <script>"../DOM/tools.js"</script>
        <script>
            let arrName = ["肖巍", "杨恩", "张芝荣", "罗雷", "郭林杰", "小湉湉", "弯弯姐", "陈锴", "徐阳", "陈阳吉", "张胜江", "我", "波哥", "阿汤哥", "谢杰", "薛老板"];
            let names = document.querySelector("h1");
            let start_btn = document.querySelector("#start_btn");
            let stop_btn = document.querySelector("#stop_btn");
            let i, timer; 

            function creatRandom(min, max) {
                if (!max) {
                    [max, min] = [min, 0];
                }
                let number = parseInt(Math.random() * (max - min + 1) + min);
                return number;
            }
            start_btn.onclick = function () {
                stop_btn.disabled ? stop_btn.disabled = false : stop_btn.disabled = true;
                start_btn.disabled ? start_btn.disabled = false : start_btn.disabled = true;
                timer = setInterval(() => {
                    i = creatRandom(0, arrName.length - 1);
                    names.innerHTML = arrName[i];
                }, 100);
            };
            stop_btn.onclick = function () {
                stop_btn.disabled ? stop_btn.disabled = false : stop_btn.disabled = true;
                start_btn.disabled ? start_btn.disabled = false : start_btn.disabled = true;
                console.log(arrName  [i]);
                clearInterval(timer);
                arrName.splice(i, 1);
                if(!arrName.length){
                    start_btn.disabled=true;
                    stop_btn.disabled=true;
                    names.innerHTML = "抽奖完毕";
                }
            };
        </script>
    </body>

    </html>
  • 相关阅读:
    POJ3928 Pingpong(统计比 K 小的个数 + 树状数组)
    C++ Primer Plus读书笔记
    HDU1698Just a Hook(线段树 + 区间修改 + 求和)
    POJ3468A Simple Problem with Integers(区间加数求和 + 线段树)
    POJ2528Mayor's posters(离散化 + 线段树)
    约瑟夫环
    编写一个JavaWeb项目
    四则运算在线答题系统
    JAVA项目中的常用的异常处理情况
    第八周动手动脑
  • 原文地址:https://www.cnblogs.com/Yangyecool/p/13171682.html
Copyright © 2011-2022 走看看