最简单的点名器纯html+css+js

 下面是我在无聊时候写的一个点名器的代码,很点单,最简单的点名器纯html+css+js,希望可以帮助到你



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点名器</title>
    <style>
    *{
        margin:0;
        padding:0;
    }

    body {
        background-image: linear-gradient(60deg, #64b3f4 0%, #c2e59c 100%);
    }

    #name {
        width: 300px;
        height: 300px;
        background:lightblue;
        border:1px solid green;
        border-radius:10px;
        margin:50px auto;
        font-size: 50px;
        text-align:center;
        line-height:300px;
    }

    .b2 {
        margin-left:430px;
    }

    button {
        margin-left:100px;
        height:50px;
        width:50px;
        
    }
    </style>
</head>
<body>
    <div id="name">
        开始点名
    </div>

<div class="b2">
    <button onclick="start()">开始</button>
    <button onclick="end()">结束</button>
</div>
</body>
<script type="text/javascript">
    // 声明变量
    var time, // 计时器
        div,
        name; // 选中的用户名

    div = document.getElementById('name');

    // 创建一个数组用来存储数据
    var name_list = ["张三","李四","王五"];

    function start(){
        // 生成一个随机数

        var num = Math.floor(Math.random() * name_list.length);

        // 根据随机索引值来确定选中的姓名

        name = name_list[num];

        // 更改网页里div的值

        div.innerHTML = name;

        // Window setTimeout() 方法
        time = setTimeout("start()",100);
    }

    function end() {

        clearTimeout(time);


        // clearTimeout() 方法可取消由 setTimeout() 方法设置的 timeout。
    }

</script>
</html>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值