JavaScript to implement random roll call web page

JavaScript to implement random roll call web page

JavaScript writes a random roll call webpage for your reference. The specific content is as follows

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
   * {
    margin: 0;
    padding: 0;
   }
   #box {
    border: 1px solid black;/*Set the border and color of the box*/
    width: 500px;
    height: 500px;
    margin: 100px auto;/*200px from the top and centered*/
    background-color: #000000;/*background color of the box*/
    position: relative;/*positioning*/
   }
   p{
    width: 500px;
    height: 200px;
    text-align: center;/*Center the text*/
    line-height: 200px;/*Set line height*/
    font-size: 80px;/*font size*/
    color: #ffff00;
   }
   #anniu {
    width: 200px;
    height: 50px;
    background-color:#00aaff;
    position: absolute;
    bottom: 100px;/*100px from the bottom*/
    left: 50%;
    margin-left: -100px;
    color: #ffffff;
    font-size: 20px
   }
  </style>
 </head>
 <body>
  <div id="box">
   <p id="wenben">Random roll call</p>
   <input type="button" value="Start roll call" id="anniu">
  </div>
 </body>
 <script>
  var wenben = document.getElementById("wenben")
  var anniu = document.getElementById("anniu")
  var timer //define timer var arr = ['Liu Yi', 'Chen Er', 'Zhang San', 'Li Si', 'Wang Wu', 'Zhao Liu', 'Sun Qi', 'Zhou Ba', 'Wu Jiu', 'Zheng Shi']
  var test = true
  anniu.onclick = function() {
   if (test) {
    start()
    anniu.innerHTML = "end"
    test = false
   } else {
    stop()
    anniu.innerHTML = "Start"
    test = true
   }
  }
  function start() { /*Start*/
   timer = setInterval(function random() {
    var index = parseInt(Math.random() * arr.length)
    wenben.innerHTML = arr[index]
   }, 50);
  }
  function stop() { /*End*/
   clearInterval(timer)
  }
 </script>
</html>

The effect is as follows:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A random roll call function implemented by javascript
  • A random roll call program using javascript
  • JS implements random and sequential roll call in class
  • js implements random roll call system (example explanation)
  • JS+CSS to achieve random roll call (example code)
  • js implements random roll call function
  • JS implements random roll caller
  • Specific analysis of the needs of implementing random roll call in class with JavaScript
  • JavaScript implementation of random roll caller
  • Detailed explanation of the example of random roll caller implemented in JavaScript

<<:  Detailed explanation of fuser command usage in Linux

>>:  Detailed explanation of the idea of ​​querying the difference between hourly data and last hourly data in MySQL

Recommend

Summary of MySQL log related knowledge

Table of contents SQL execution order bin log Wha...

Application scenarios and design methods of MySQL table and database sharding

Many friends have asked in forums and message are...

The corresponding attributes and usage of XHTML tags in CSS

When I first started designing web pages using XH...

How to install and configure SSH service in Ubuntu 18.04

Install ssh tool 1. Open the terminal and type th...

MySQL 5.7.18 free installation version configuration tutorial

MySQL 5.7.18 free installation version installati...

Use render function to encapsulate highly scalable components

need: In background management, there are often d...

100-1% of the content on the website is navigation

Website, (100-1)% of the content is navigation 1....

Usage of HTML H title tag

The usage of H tags, especially h1, has always bee...

About the IE label LI text wrapping problem

I struggled with this for a long time, and after s...

Detailed Example of Row-Level Locking in MySQL

Preface Locks are synchronization mechanisms used...

Detailed explanation of Linux command file overwrite and file append

1. The difference between the command > and &g...

Limiting the number of short-term accesses to a certain IP based on Nginx

How to set a limit on the number of visits to a c...

OpenSSL implements two-way authentication tutorial (with server and client code)

1. Background 1.1 Problems A recent product testi...