Example code for implementing random roll caller in html

Example code for implementing random roll caller in html

After this roll call device starts calling the roll, you need to click the stop button to complete the call, because it is a simplified version and does not take into account the need for automatic stopping. The name data is stored in the form of a string, which is suitable for a small range of roll calls. If there is a large demand, you can make appropriate improvements yourself.

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random roll call generation</title>

    <style>
        /* Page css style */
        .wrapper {
            width: 800px;
            margin: 100px auto;
            border: 1px solid #ddd;
            text-align: center;
        }

        .box li {
            vertical-align: top;
            display: inline-block;
            width: 100px;
            height: 50px;
            border: 2px solid #ddd;
            border-radius: 15px;
            text-align: center;
            line-height: 50px;
            margin: 5px;
        }
        
        .wrapper button {
            border: none;
            width: 100px;
            height: 50px;
            border-radius: 10px;
            cursor: pointer;
            outline: none;
            margin-top: 20px;
            font-weight: bold;
            color: #333;
            background-color: rgb(14, 146, 43);
        }

        .wrapper button {
            display: inline-block;
        }

        body {
            background-color: #eee;
        }
    </style>

</head>

<body>
    <div class="wrapper">
     <h1 align="center">Random roll call system</h2>
      //Real-time display of system time tag<h6 id="data" align="right"></h6>
        <ul class="box"></ul>
        <button class="start">Start</button>
        <button class="stop">Stop</button>
    </div>
</body>

<script>
    //Define global variables for easy reference var boxUl = document.getElementsByClassName('box')[0];
    var start = document.getElementsByClassName('start')[0];
    var stop = document.getElementsByClassName('stop')[0]
    var oLi = document.getElementsByTagName('li');

    //Data preparation var nameString = new String("Zhang San, Li Si, Wang Wu, Zhao Liu, Zhou Qi, Tian Ba, Guo Jiu, return to zero, Zhang 3, Li 4, Wang 5, Zhao 6, Zhou 7, Tian 8, Guo 9, return to 0");
    var nameArr = nameString.split(",");

    //Get each student's name and add it to the label, automatically parse the HTML tag var str = "";
    for (let i = 0; i < nameArr.length; i++) {
        str += "<li >" + nameArr[i] + "</li>"
    }
    boxUl.innerHTML = str;

    //Add the click event of the start button var timer = null;
    start.onclick = function () {
        // Set the timer timer = setInterval(function () {

            // Generate random numbers based on the length range of the array var i = Math.floor(Math.random() * nameArr.length);
            // First clear all style attributes through the for loop for (var j = 0; j < oLi.length; j++) {
                oLi[j].removeAttribute("style");
            }
            // Color attribute for randomly selected li oLi[i].style.background = "red";
        }, 150);
    };
    // Click to stop stop.onclick = function () {
        // Clear the timer and stop calling clearInterval(timer);
    }
    //Page initialization time setting window.onload = function () {
        datatime();
    }
    //Dynamic refresh of page time setInterval(datatime, 1000);

    function datatime() {
        let data = new Date();
        let dataString = "Now it is Beijing time: " + data.toLocaleString();
        document.getElementById("data").innerHTML = dataString;
    }
</script>

Attached is a rendering

This is the end of this article about the sample code of HTML to implement random roll call device. For more relevant HTML random roll call device content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<: 

>>:  Split and merge tables in HTML (colspan, rowspan)

Recommend

MySQL briefly understands how "order by" works

For sorting, order by is a keyword we use very fr...

Detailed steps for installing and debugging MySQL database on CentOS7 [Example]

This example requires downloading and installing ...

Multiple methods to modify MySQL root password (recommended)

Method 1: Use the SET PASSWORD command MySQL -u r...

MySQL slow log online problems and optimization solutions

MySQL slow log is a type of information that MySQ...

Docker build PHP environment tutorial detailed explanation

Docker installation Use the official installation...

MySQL SQL statement analysis and query optimization detailed explanation

How to obtain SQL statements with performance iss...

CSS3 animation – steps function explained

When I was looking at some CSS3 animation source ...

WeChat applet implements video player sending bullet screen

This article shares the specific code for WeChat ...

Record a slow query event caused by a misjudgment of the online MySQL optimizer

Preface: I received crazy slow query and request ...

A complete example of implementing a timed crawler with Nodejs

Table of contents Cause of the incident Use Node ...

25 Ways and Tips to Increase Web Page Loading Speed

Introduction <br />Not everyone has access t...

Web Design Tutorial (7): Improving Web Design Efficiency

<br />Previous article: Web Design Tutorial ...

A quick guide to Docker

Docker provides a way to automatically deploy sof...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...

Docker private warehouse harbor construction process

1. Preparation 1.1 harbor download harbor downloa...