<!DOCTYPE html>
<html>
<head>
	<title>HTML点名器</title>
	<script>
		var studentList = ["A", "B", "C", "D"]; // 学生名单
		var chosenList = []; // 已选学生名单
		var timer; // 定时器
<pre><code>	function start() {
		timer = setInterval(function() {
			var randomIndex = Math.floor(Math.random() * studentList.length); // 生成随机数
			var chosenStudent = studentList[randomIndex]; // 选中学生
			chosenList.push(chosenStudent); // 将已选学生添加到列表中
			document.getElementById(&quot;result&quot;).innerHTML = chosenList.join(&quot;, &quot;); // 显示已选学生
		}, 100); // 每100毫秒抽一次
	}

	function stop() {
		clearInterval(timer); // 停止定时器
	}
&lt;/script&gt;
</code></pre>
</head>
<body>
	<h1>HTML点名器</h1>
	<p>从A,B,C,D四个学生中抽出三个</p>
	<button onclick="start()">开始</button>
	<button onclick="stop()">完成</button>
	<p>已选学生名单:</p>
	<p id="result"></p>
</body>
</html

原文地址: https://www.cveoy.top/t/topic/e9Aq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录