JavaScript随机抽奖

本文介绍了一个简单的随机抽奖程序,使用HTML、CSS和JavaScript实现。页面包括一个显示抽奖结果的区域及开始和结束按钮,通过定时器实现随机切换效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>随机抽奖</title>
    <style>
        .box{width:600px;height:500px;margin:0 auto;border:dashed #ccc 2px;}
        button{width:120px;height:40px;border-radius: 10px;margin:30px auto;font-size: 26px;display: block;}
        span{width:300px;height:300px;background:#ffff99;display: block;margin:0 auto;border-radius:100%;text-align: center;font-size:30px;line-height:300px;}
    </style>
    <script>
        var a1=["林惊羽","曾书书","碧瑶","张小凡","无崖子","鬼王"];

        var times;
        function star(){

            var index=parseInt(Math.random()*a1.length);
            var x=a1[index];
            var s=document.getElementById("show");
            s.innerHTML=x;


        }
        function start(){
            times=setInterval(star,40);
        }
        function end(){
            clearInterval(times);
        }
    </script>

</head>
<body>
<div class="box">
    <span id="show">等待抽奖</span>
    <button onclick="start()">开始抽奖</button>
    <button onclick="end()">结束抽奖</button>

</div>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值