本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器效果圖的具體代碼,供大家參考,具體內(nèi)容如下
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供婁煩企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為婁煩眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
js實(shí)現(xiàn)隨機(jī)點(diǎn)名器的思路
利用setTimeout()計(jì)時(shí)器實(shí)現(xiàn)隨機(jī)的效果,功能函數(shù)
function show(){ var box=window.document.getElementById("box"); var num=Math.floor((Math.random()*100000))%namelist.length; box.innerHTML=namelist[num]; mytime=setTimeout("show()",1); }
完整代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>點(diǎn)擊按鈕隨機(jī)點(diǎn)名-樣式布局參考</title> <style type="text/css"> #box { margin: auto; width: 660px; font-size: 66px; height: 94px; color: #138eee; text-align: center; margin-top: 200px; } #bt { margin: auto; width: 200px; text-align: center; margin-top: 75px; color: #fff; font-size: 25px; cursor: pointer; } </style> <script type="text/javascript"> var namelist=["張三","李四","王五","趙六","孫七"]; var mytime=null; function doit(){ var bt=window.document.getElementById("bt"); if(mytime==null){ bt.innerHTML="停止"; show(); } else{ bt.innerHTML="開(kāi)始點(diǎn)名"; clearTimeout(mytime); mytime=null; } } function show(){ var box=window.document.getElementById("box"); var num=Math.floor((Math.random()*100000))%namelist.length; box.innerHTML=namelist[num]; mytime=setTimeout("show()",1); } </script> </head> <body id="bodybj" > <div id="box">親,準(zhǔn)備好點(diǎn)名了嗎?</div> <div id="bt" onclick="doit()">開(kāi)始點(diǎn)名</div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
文章題目:JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器
標(biāo)題鏈接:http://muchs.cn/article10/ijsogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)、做網(wǎng)站、品牌網(wǎng)站制作、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)