<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>点名</title>
    <script>
      var students = ["A", "B", "C", "D"];
      var selected = [];
      var intervalId;
<pre><code>  function start() {
    var button = document.getElementById(&quot;startButton&quot;);
    button.disabled = true;
    intervalId = setInterval(function() {
      var index = Math.floor(Math.random() * students.length);
      var student = students[index];
      selected.push(student);
      document.getElementById(&quot;result&quot;).innerHTML = student;
    }, 500);
  }

  function stop() {
    clearInterval(intervalId);
    var button = document.getElementById(&quot;startButton&quot;);
    button.disabled = false;
    document.getElementById(&quot;finalResult&quot;).innerHTML = selected.join(&quot;, &quot;);
  }
&lt;/script&gt;
</code></pre>
  </head>
  <body>
    <h1>点名</h1>
    <p>从A,B,C,D四个学生中抽出三个</p>
    <p id="result"></p>
    <button id="startButton" onclick="start()">开始</button>
    <button onclick="stop()">完成</button>
    <p id="finalResult"></p>
  </body>
</html

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

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