Loading... <p><!doctype html><br><html></p><p><head></p><pre><code><meta charset="utf-8"> <title>无标题文档</title> <script> window.onload = function() { const prize = ['自行车', '微波炉', '电视机', '洗衣机', '100万元大奖', '10万元大奖']; //奖项 let b = document.getElementById('a'); //内容 let on = document.getElementById('on'); //抽奖暂停 let off = document.getElementById('off'); //抽奖继续 let start = null; //定时器重置 let cs = document.getElementById('cs'); //次数 let csi = cs.innerHTML; //次数的内容 let i = 3; //可以进行抽奖的次数 //console.log(a.length) function cj() { let x = Math.random(); x = Math.ceil(x * prize.length - 1); //console.log(a[x]) b.innerHTML = prize[x]; } start = setInterval(cj, 60); //定时器启动 on.onclick = function() { if (i < 1) { alert("您的抽奖次数为0") } else { clearInterval(start); i--; } if (a.innerHTML.includes("谢谢参与")) {} else { //如果不是谢谢参与,则生成一个1,2的随机数如果这个随机数是二则再来一次,如果不是则谢谢参与 let y = Math.random(); y = Math.ceil(y * 2); if (y === 2) { a.innerHTML = "再来一次"; i++; } else { a.innerHTML = "谢谢参与"; } } } off.onclick = function() { if (i < 1) { alert("您的抽奖次数为0") } else { start = setInterval(cj, 50); //定时器 } } setInterval(function() { cs.innerHTML = csi + i; // console.log(i); }, 100) } </script></code></pre><p></head></p><p><body></p><pre><code><p id="cs">剩余抽奖次数</p> <div id="a"></div> <input type="button" value="抽奖" id="on"> <input type="button" value="继续" id="off"></code></pre><p></body></p><p></html></p><p>抽到prize里面的东西概率为0!<br>这很pdd <img src="https://cdn.xxhzm.cn/2595557847/handsome/9.0.2/img/emotion/aru/thumb.png" class="emotion-aru"></p> 猜你想看 vscode常用快捷键 nux2对比nuxt3 每日一学:PHP 中的array_uintersect_uassoc函数详解 铭记历史,九一八事件! Linux安装Siege 每日一学:PHP 中的array_count_values函数详解 FFmpeg 和 FFprobe 在 Linux 系统上的安装指南 ES6箭头函数this指向 react学习-环境初始化(一) Go自定义error 最后修改:2022 年 06 月 05 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏
3 条评论
???教程呢
这就是一个抽奖啊直接可以使用的