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

CSS style does not work (the most complete solution summary in history)

When we write pages, we sometimes find that the C...

Detailed explanation on how to deploy H5 games to nginx server

On the road to self-learning game development, th...

Example code for implementing dynamic skinning with vue+element

Sometimes the theme of a project cannot satisfy e...

iframe parameters with instructions and examples

<iframe src=”test.jsp” width=”100″ height=”50″...

Analysis of the causes of accidents caused by Unicode signature BOM

Maybe you are using include files here, which is u...

JS interview question: Can forEach jump out of the loop?

When I was asked this question, I was ignorant an...

Three ways to forward linux ssh port

ssh is one of the two command line tools I use mo...

MySQL Flush-List and dirty page flushing mechanism

1. Review The Buffer Pool will be initialized aft...

How to authorize all the contents of a folder to a certain user in Linux?

【Problem Analysis】 We can use the chown command. ...

Details on using JS array methods some, every and find

Table of contents 1. some 2. every 3. find 1. som...

How InnoDB cleverly implements transaction isolation levels

Preface In the previous article Detailed Explanat...

Details on using order by in MySQL

Table of contents 1. Introduction 2. Main text 2....

How does MySQL implement ACID transactions?

Preface Recently, during an interview, I was aske...