原生js實(shí)現(xiàn)隨機(jī)點(diǎn)名
本文實(shí)例為大家分享了js實(shí)現(xiàn)隨機(jī)點(diǎn)名的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>隨機(jī)點(diǎn)名</title> </head> <body> <h1 class="name" id="names">點(diǎn)名</h1> <input type="button" value="開始" id=start_btn> <input type="button" value="結(jié)束" id=stop_btn disabled> <script>"../DOM/tools.js"</script> <script> let arrName = ["肖巍", "楊恩", "小菊花", "二狗", "小強(qiáng)", "小湉湉", "彎彎姐", "陳鍇", "徐陽", "陳陽吉", "張勝江", "我", "波哥", "阿湯哥", "杰哥", "薛老板"]; let names = document.querySelector("h1"); let start_btn = document.querySelector("#start_btn"); let stop_btn = document.querySelector("#stop_btn"); let i, timer; function creatRandom(min, max) { if (!max) { [max, min] = [min, 0]; } let number = parseInt(Math.random() * (max - min + 1) + min); return number; } start_btn.onclick = function () { stop_btn.disabled ? stop_btn.disabled = false : stop_btn.disabled = true; start_btn.disabled ? start_btn.disabled = false : start_btn.disabled = true; timer = setInterval(() => { i = creatRandom(0, arrName.length - 1); names.innerHTML = arrName[i]; }, 100); }; stop_btn.onclick = function () { stop_btn.disabled ? stop_btn.disabled = false : stop_btn.disabled = true; start_btn.disabled ? start_btn.disabled = false : start_btn.disabled = true; console.log(arrName [i]); clearInterval(timer); arrName.splice(i, 1); if(!arrName.length){ start_btn.disabled=true; stop_btn.disabled=true; names.innerHTML = "抽獎(jiǎng)完畢"; } }; </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js實(shí)現(xiàn)隨機(jī)點(diǎn)名器精簡(jiǎn)版
- JS實(shí)現(xiàn)隨機(jī)點(diǎn)名器
- JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名程序
- JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器
- js實(shí)現(xiàn)課堂隨機(jī)點(diǎn)名系統(tǒng)
- JavaScript實(shí)現(xiàn)簡(jiǎn)單隨機(jī)點(diǎn)名器
- js實(shí)現(xiàn)隨機(jī)點(diǎn)名程序
- 原生js實(shí)現(xiàn)隨機(jī)點(diǎn)名功能
- javascript網(wǎng)頁隨機(jī)點(diǎn)名實(shí)現(xiàn)過程解析
- javascript如何使用函數(shù)random來實(shí)現(xiàn)課堂隨機(jī)點(diǎn)名方法詳解
相關(guān)文章
confirm的用法示例用于按鈕操作時(shí)確定是否執(zhí)行
這篇文章主要介紹了confirm的用法,confirm一般用于按鈕操作時(shí)確定是否執(zhí)行,需要的朋友可以參考下2014-06-06JS判斷、校驗(yàn)MAC地址的2個(gè)實(shí)例
這篇文章主要介紹了JS判斷、校驗(yàn)MAC地址的2個(gè)實(shí)例,需要的朋友可以參考下2014-05-05JS代碼判斷IE6,IE7,IE8,IE9的函數(shù)代碼
JS代碼判斷瀏覽器版本,支持IE6,IE7,IE8,IE9!做網(wǎng)頁有時(shí)候會(huì)用到JS檢測(cè)IE的版本,下面是檢測(cè)Microsoft Internet Explorer版本的三種代碼2013-08-08封裝運(yùn)動(dòng)框架實(shí)戰(zhàn)左右與上下滑動(dòng)的焦點(diǎn)輪播圖(實(shí)例)
下面小編就為大家?guī)硪黄庋b運(yùn)動(dòng)框架實(shí)戰(zhàn)左右與上下滑動(dòng)的焦點(diǎn)輪播圖(實(shí)例)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10復(fù)制網(wǎng)頁內(nèi)容,粘貼之后自動(dòng)加上網(wǎng)址的實(shí)現(xiàn)方法(腳本之家特別整理)
復(fù)制內(nèi)容加網(wǎng)址的功能,自06年腳本之家將這個(gè)功能發(fā)布并通過blueidea宣傳以后,現(xiàn)如今很多網(wǎng)站都使用上了, 當(dāng)初我們也由這個(gè)功能帶來很多外鏈2014-10-10