原生JS点名器

<!DOCTYPE type='html'>
<html>
    <head>
        <title>js点名器</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <style type="text/css">

            * {
                margin: 0px;
                padding: 0px;
                border: 0px;
            }
            #name {
                position: relative;
                width: 200px;
                height: 80px;
                top: 50px;
                background-color: greenyellow;
                border-radius: 5px;
                left: 10px;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 40px;
                border: grey solid 1px;
            }
            #start {
                position: relative;
                width: 200px;
                height: 60px;
                top: 240px;
                background-color: blue;
                display: flex;
                justify-content: center;
                align-items: center;
                border-radius: 25px;
                font-size: 30px;
                cursor: pointer;
                border: red solid 1px;
            }
        </style>
    </head>
    <body>
    <center>
        <div style="width: 400px;height: 400px;border: red solid 2px;">
            <center><div id="name"></div></center>

           <button id="start">开始</button>
        </div>
    </center>
        <script type="text/javascript">
            var namelist = ["乔峰", "段誉", "虚竹", "丁春秋", "慕容复", "慕容博", "萧远山", "南海鳄神","鸠摩智","天山童姥"];
            var start = document.getElementById("start");
            var name  = document.getElementById('name');
            start.onclick=function () {
                var startname = start.innerHTML;
                if(startname == '开始'){
                    start.innerHTML = '结束';
                    timeId = setInterval(function(){
                        var num = (parseInt(Math.random()*10));
                        document.getElementById('name').innerHTML = namelist[num];
                    },200);
                }else{
                    start.innerHTML = '开始';
                    clearInterval(timeId);
                }
            }

        </script>
    </body>

</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值