本文实例为大家分享了js实现随机点名的具体代码,供大家参考,具体内容如下
代码:
<!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>刘志远</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 = [\'刘志远\', \'万策\', \'李博文\', \'曹建莹\', \'张佳祺\', \'赵瑞瑞\', \'陈全虎\', \'胡金朋\', \'耿建丽\', \'王如雪\', \'王振涛\', \'刘放\', \'张亚迪\', \'朱翔煜\', \'王奥\', \'薛澳飞\', \'刘志玮\', \'胡高洋\', \'周畅\', \'赵英杰\', \'徐亚美\', \'郑勇超\', \'闻吉祥\', \'王阿雨\', \'陈德帅\', \'申林益\', \'赵艳哲\', \' 肖梦飞\', \'鲍尔欣\', \'代星澳\', \'汪青\', \'谢森成\', \'雷吕能\', \'丁康宁\', \'杨泽文\', \'王永杰\', \'侯振强\', \'马建成\', \'朱保森\', \'王皓圆\', \'孙秀婷\', \'靳丹丹\', \'李聪\', \'纪妍\', \'苏文璇\']; 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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
© 版权声明
THE END
暂无评论内容