Native JavaScript to implement random roll call table

Native JavaScript to implement random roll call table

This article example shares the specific code of the JavaScript random roll call table for your reference. The specific content is as follows

Effect:

Code:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title></title>
 <style>
  .box{
  width:300px;
  height:200px;
  border:1px solid #ccc;
  /*position: absolute;
  left:0;
  right:0;
  top:0;
  bottom:0;
  margin: auto;*/
  margin: 100px auto;
  text-align: center;
  }
  h1{
  width:150px;
  height:60px;
  line-height: 60px;
  text-align: center;
  font-size: 30px;
  background-color: red;
  margin: 10px auto;
  }
  button{
  width:100px;
  height:40px;
  background-color: dodgerblue;
  border:0;
  font-size: 24px;
  color:#fff;
  }
  
  
 </style>
 </head>
 <body>
 <div class="box">
  <h1></h1>
  <button>Start</button>
  <button>Stop</button>
 </div>
 <script>
  var h1=document.getElementsByTagName('h1')[0];
  var btn = document.getElementsByTagName("button");
  var arr=["Su Chenxu","Zhang Zhiyang","Xiao Ming","Social Brother Kun","Yao","Jing Zhen","Jin Tao","Network Manager","Social Brother Chen","Zha Nan","Xue","Baby Man","Big Guy","Sleeping God","Long Ye","Ying Er","Northeast Baby","Ke Ke","Very Young Girl","Gou Dan","Gou Zi","Tian Jiao","Zhi Qiang","Jin Wei","Haitao","Sister Mai","Xin Feng","Sister Huan","Er Gou"];
  
  var ind = ranFun(0,arr.length-1)
  
  h1.innerHTML=arr[ind];
  var timer;
  btn[0].onclick=function(){
  clearInterval(timer)
  timer = setInterval(function(){
   h1.innerHTML=arr[ranFun(0,arr.length-1)]
  },100)
  }
  
  btn[1].onclick=function(){
  clearInterval(timer)
  }
  
  function ranFun(a,b){
  return Math.floor(Math.random()*(b-a+1)+a)
  }
 </script>
 </body>
</html>

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 roll call system (example explanation)
  • JS implements random and sequential roll call in class
  • Code in js to use DOM to copy (clone) the specified node name data to a new XML file
  • js implements random roll call function
  • JS+CSS to achieve random roll call (example code)
  • Specific analysis of the needs of implementing random roll call in class with JavaScript
  • Detailed explanation of the example of random roll caller implemented in JavaScript
  • js implements the method of editing div node name

<<:  The main idea of ​​​​dynamically setting routing permissions in Vue

>>:  Sharing tips on using vue element and nuxt

Recommend

Use of Linux dynamic link library

Compared with ordinary programs, dynamic link lib...

CSS3 uses animation attributes to achieve cool effects (recommended)

animation-name animation name, can have multiple ...

Detailed explanation of the use of the clip-path property in CSS

Use of clip-path polygon The value is composed of...

Solve the problem that IN subquery in MySQL will cause the index to be unusable

Today I saw a case study on MySQL IN subquery opt...

Vue sample code for easily implementing virtual scrolling

Table of contents Preface Rolling principle accom...

Detailed explanation of the knowledge points of using TEXT/BLOB types in MySQL

1. The difference between TEXT and BLOB The only ...

Pure CSS3 realizes the effect of div entering and exiting in order

This article mainly introduces the effect of div ...

MySQL trigger principle and usage example analysis

This article uses examples to explain the princip...

The rel attribute of the HTML link tag

The <link> tag defines the relationship bet...

HTML markup language - table tag

Click here to return to the 123WORDPRESS.COM HTML ...

Vue3 setup() advanced usage examples detailed explanation

Table of contents 1. Differences between option A...

jQuery implements simple button color change

In HTML and CSS, we want to set the color of a bu...

Summary of using MySQL isolation columns and prefix indexes

Table of contents Isolate Data Columns Prefix Ind...

MySQL 5.7.24 installation and configuration graphic tutorial

This article shares the installation and configur...

Ubuntu16.04 builds php5.6 web server environment

Ubuntu 16.04 installs the PHP7.0 environment by d...