js實現(xiàn)隨機點名
本文實例為大家分享了js實現(xià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>Document</title> <style> div:nth-child(1) { width: 200px; height: 100px; background-color: burlywood; text-align: center; line-height: 100px; } div:nth-child(2) { width: 100px; height: 100px; background-color: pink; border-radius: 50%; text-align: center; line-height: 100px; } </style></head> <body> <div>劉志遠(yuǎn)</div> <div>開始</div> <script> var div = document.getElementsByTagName(’div’); var btn = document.getElementsByTagName(’button’)[0]; username() function username() { var flag = false; var timerId = null; // console.log(div); var arr = [’劉志遠(yuǎn)’, ’萬策’, ’李博文’, ’曹建瑩’, ’張佳祺’, ’趙瑞瑞’, ’陳全虎’, ’胡金朋’, ’耿建麗’, ’王如雪’, ’王振濤’, ’劉放’, ’張亞迪’, ’朱翔煜’, ’王奧’, ’薛澳飛’, ’劉志瑋’, ’胡高洋’, ’周暢’, ’趙英杰’, ’徐亞美’, ’鄭勇超’, ’聞吉祥’, ’王阿雨’, ’陳德帥’, ’申林益’, ’趙艷哲’, ’ 肖夢飛’, ’鮑爾欣’, ’代星澳’, ’汪青’, ’謝森成’, ’雷呂能’, ’丁康寧’, ’楊澤文’, ’王永杰’, ’侯振強’, ’馬建成’, ’朱保森’, ’王皓圓’, ’孫秀婷’, ’靳丹丹’, ’李聰’, ’紀(jì)妍’, ’蘇文璇’]; div[1].onclick = function() { if (flag) { clearInterval(timerId); div[1].innerHTML = ’停止’ flag = false; } else { timerId = setInterval(function() { var re = Math.floor(Math.random() * arr.length); console.log(re); div[0].innerHTML = arr[re]; }, 60); div[1].innerHTML = ’開始’ flag = true; } } } </script></body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 怎樣才能用js生成xmldom對象,并且在firefox中也實現(xiàn)xml數(shù)據(jù)島?2. 基于javaweb+jsp實現(xiàn)企業(yè)車輛管理系統(tǒng)3. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼4. 利用ajax+php實現(xiàn)商品價格計算5. jstl 字符串處理函數(shù)6. JSP動態(tài)網(wǎng)頁開發(fā)原理詳解7. .Net core Blazor+自定義日志提供器實現(xiàn)實時日志查看器的原理解析8. PHP中為什么使用file_get_contents("php://input")接收微信通知9. IOS蘋果AppStore內(nèi)購付款的服務(wù)器端php驗證方法(使用thinkphp)10. XML CDATA是什么?
