国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

js實(shí)現(xiàn)簡(jiǎn)單抽獎(jiǎng)功能

瀏覽:206日期:2024-04-21 11:59:07

本文實(shí)例為大家分享了js實(shí)現(xiàn)簡(jiǎn)單抽獎(jiǎng)功能的具體代碼,供大家參考,具體內(nèi)容如下

代碼

<!DOCTYPE html><html> <head> <meta charset='utf-8' /> <title></title> <style> #box{ border: 1px solid aqua; height: 100px; width: 200px; text-align: center; line-height: 100px; margin: auto; font-size: 22px; } .active{ background: slateblue; } li{ text-align: center; list-style:none ; width: 40px; height: 20px; line-height: 20px; border: 1px solid blue; margin-left: 40px; float: left; } ul,li { list-style: none; } #shu { margin: auto; } </style> </head> <body> <button id='stp'>開始</button><button id='off'>停止</button> <div id='box'>恭喜<span>1</span>號(hào) </div> <div id='shu'>0</div><span>等獎(jiǎng)</span> <ul> <li class='active'>1號(hào)</li> <li>2號(hào)</li> <li>3號(hào)</li> <li>4號(hào)</li> <li>5號(hào)</li> <li>6號(hào)</li> <li>7號(hào)</li> </ul> <script> var t=null; var ostp=document.getElementById('stp'); var ooff=document.getElementById('off'); var ospan=document.getElementsByTagName('div')[0].getElementsByTagName('span'); var oli=document.getElementsByTagName('ul')[0].getElementsByTagName('li'); var oshu=document.getElementsByClassName('shu'); function mytime(){ var n=Math.floor(Math.random()*7+1); ospan[0].innerText=n; ospan[1].innerText=oli[n-1].innerText; for(let i=0;i<oli.length;i++) { oli[i].className=''; } oli[n-1].className='active'; } function mytime2() { var a=Math.floor(Math.random()*3+1); shu.innerText=a; } ostp.onclick=function(){ clearInterval(t); t=setInterval(mytime,50); at=setInterval(mytime2,1000) } ooff.onclick=function(){ clearInterval(t); clearInterval(at); } </script> </body></html>

效果

js實(shí)現(xiàn)簡(jiǎn)單抽獎(jiǎng)功能

js實(shí)現(xiàn)簡(jiǎn)單抽獎(jiǎng)功能

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 岳普湖县| 嘉义县| 民丰县| 洛隆县| 越西县| 团风县| 阜阳市| 江北区| 瓮安县| 洛阳市| 习水县| 阜阳市| 申扎县| 云霄县| 乌拉特前旗| 克什克腾旗| 高碑店市| 榆树市| 凭祥市| 景宁| 普定县| 保靖县| 白朗县| 高碑店市| 桐庐县| 邹平县| 西昌市| 永州市| 额尔古纳市| 哈巴河县| 锡林郭勒盟| 嘉峪关市| 白山市| 秦皇岛市| 剑河县| 平遥县| 许昌县| 襄垣县| 定远县| 建水县| 花莲县|