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:
|
<<: Detailed explanation of fuser command usage in Linux
When laying out the page, in order to give users ...
Table of contents SQL execution order bin log Wha...
Many friends have asked in forums and message are...
When I first started designing web pages using XH...
Install ssh tool 1. Open the terminal and type th...
1. Introduction When the amount of data in the da...
MySQL 5.7.18 free installation version installati...
need: In background management, there are often d...
Website, (100-1)% of the content is navigation 1....
The usage of H tags, especially h1, has always bee...
I struggled with this for a long time, and after s...
Preface Locks are synchronization mechanisms used...
1. The difference between the command > and &g...
How to set a limit on the number of visits to a c...
1. Background 1.1 Problems A recent product testi...