html+css+JavaScript点名器

运行效果:

代码如下:

html 复制代码
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机点名</title>
</head>
<style>

    body{
        background-image: url(img/bg.png);
        }

    .big{
       background-color: aliceblue;
       width:400px;
       height: 500px;
       border-radius: 30px;
       margin: 50px auto;
       padding-top: 20px;
        }

    .title{
        font-size: 50px;
        text-align: center; 
        font-weight: 520;
            }

    #show {
        width: 300px;
        height: 200px;
        background-color: aliceblue;
        line-height: 200px;
        font-size: 30px;
        text-align: center;
        border: 1.5px solid black;
        border-radius: 10px;
        margin: 20px auto;
    }

    .button{
        margin: 10px 85px;
    }
    .start{
       height: 40px;
       margin: auto;
       width: 100px;
    }
    .end{
        margin-left:20px; 
        height: 40px;
        width: 100px;
    }

    #div1 {
        width: 350px;
        height: 50px;
        background-color: aliceblue;
        line-height: 50px;
        text-align: center;
        font-size: 30px;
        border: 1px solid black;
        margin: 20px auto;
    }
    .footer{
        text-align: right;
    }

</style>
<body>
    <div class="big" >
        <div class="title">随机点名</div>
        <div id="show"></div>
        <div class="button">
            <button class="start" onclick="startName()" >开始点名</button>
            <button class="end" onclick="endName()" >结束点名</button>
        </div>  
        <div id="div1"></div>
    </div>
</body> 
<script>    
    var names = ['张三', '李四', '王五', 
                 '张杰', '谢娜', '何炅', 
                 '李维嘉', '吴昕', '杜海涛', 
                 '沈梦辰', '王一博', '肖杰'];
    var interval;
    var div1 = document.querySelector('#div1');
    var show = document.querySelector('#show');
    var number;
    show.innerHTML="亲,准备后点名了吗?";

    function startName() {
        clearInterval(interval);
        interval = setInterval(function () {
            number = Math.random() * (names.length - 1);
            number = Math.round(number);
            show.innerHTML = names[number];
        }, 50);
    };

    function endName() {
        clearInterval(interval);
        div1.innerHTML = "请"+names[number]+"同学回答问题";
    };
</script>

<footer class="footer">
    king
</footer>
 
</html>

资源下载地址:

【免费】html+css+JavaScript点名器资源-CSDN文库

相关推荐
程序员大阳4 小时前
副队长JavaScript教程(50)-DOM:网页开发的起点
javascript·dom·es·节点·概念·document·关系
沫璃染墨8 小时前
从零入门计算机网络系列(十一):HTTP协议进阶——从重定向原理到GET/POST与Fiddler抓包
linux·服务器·开发语言·网络·c++·tcp/ip·html
香芋芋圆9 小时前
iD-editor 详解|OSM官方在线编辑器,基于D3.js的轻量地图编辑器
开发语言·javascript·编辑器
晗夜未央11 小时前
任务队列反复失败,先分清重试、阻塞和结果待核对
开发语言·javascript
jktantan11 小时前
每个节点 41 字节:把一棵百万节点树拆进 14 个 typed array
前端·javascript·vue.js·算法·typescript
我命由我1234512 小时前
访客系统形式(有用户概念、无用户概念)
java·开发语言·前端·javascript·python·产品运营·产品经理
程序员大阳13 小时前
副队长JavaScript教程(65)-详解JSON:轻量级数据交换格式
javascript·json·序列化·反序列化·stringify·parse
paopaokaka_luck14 小时前
基于springboot+vue的益暖微光公益服务平台(DeepSeek公益助手、善款信息追溯、志愿服务积分闭环、ECharts运营分析、活动状态自动流转)
java·前端·javascript·spring boot·mysql·架构·echarts
栀椩14 小时前
Electron 内嵌页面跨域问题(CORS/PNA)解决全记录
前端·javascript·electron
前端架构师-老李15 小时前
HTML与CSS基础第五课—HTML的空格、换行、横线相关知识
前端·css·html