html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点名</title>
<script src="Roll-Call.js"></script>
</head>
<style>
p {
font-size: 20px;
}
body {
text-align: center;
}
#box {
margin-top: 100px;
}
#name {
font-size: 25px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<p>点名神器</p>
<div id="name">点名即将开始!</div>
<input type="button" id="control" value="开始" onclick="startorstop()">
</body>
</html>
js
var time = null;
var list = "一休,小二,张三,李四,王五,赵六,零零七,八戒,久伴,世界".split(",");
var bol = false;
function startRun() {
var i = Math.random() * list.length;
i = Math.floor(i);
document.getElementById("name").innerText = list[i];
document.getElementById("control").value = "停止";
time = setTimeout("startRun()",10);
}
function stopRun() {
if (time != null)
document.getElementById("control").value = "开始";
clearTimeout(time);
}
function startorstop() {
if (bol)
stopRun();
else
startRun();
bol = !bol;
}
图片: