Without further ado, just upload the code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Random name</title> <style type="text/css"> td{ text-align: center; } </style> </head> <body> <table width="760" border="1" height="460" align="center"> <h1 align="center">Random name系统</h1> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> <div align="center"> <br/> <br/> <input type="button" value="Random Draw" onclick="selectRandom();"/> <input type="button" value="Spread order" onclick="Upsetorder();"/> <br/> <br/> <input type="button" value="Quick Draw" onclick="Quickextr();"/> <input type="button" value="Stop Extraction" onclick="Stopextr();"/> </div> <script type="text/javascript"> var classMate = ["Zhou Yuankang","Liu Tingting","Dina","Fan Kai","Xiang Bin", "Hu Bo","Hu Hui","Huangyuan Ping","Liu Yun","Liu Jiaxin", "Zhao Fuquan","My sister Wang","Su Wei","Li Hui","Zeng Wei", "Li Jiaxiao","Zhong Shiwen","Zhang Zhiqiang","Yuan Xinhao","Yu Richeng", "Fu Lijin","Peng Fukang","Deng Huijia","Cao Rong","Liu Weidong", "Gui Yi","Peng Junbin","Zhou Kanghua","Cao Zeng","Jiang Yu"]; //Define a variable to store a random arrayvar indexArr; //Discontinue orderfunction Upsetorder(){ alert(1); //Initialize the arrayindexArr = []; //Get new random numbervar rd = parseInt(()*); while(true){ do{ var falg = true; //Loop to get each subscriptfor (var i = 0 ; i < ; i++) { //Judge whether this subscript already exists, whether it is a duplicate and then jump outif(indexArr[i] == rd){ falg = false; break; } } //Judge whether to addif(falg){ (rd); } rd = parseInt(()*); }while (falg); if( == ){ break; } } } //Random drawfunction selectRandom(){ var allTd = ("td"); for (var i = 0; i < ; i++) { allTd[i].innerHTML = classMate[indexArr[i]]; allTd[i]. = "#ff6633"; allTd[i]. = "#ff6633"; allTd[i].onclick = function (){ = "white"; } } } //Quick drawvar interId; var count = 0; //Save the selected personvar myChecked = []; var allTd = ("td"); function Quickextr(){ if(interId){ return; } //Restore all tds to the originalinterId = setInterval(function(){ for (var i = 0; i < ; i++) { allTd[i]. = "#ff6633"; allTd[i]. = "#ff6633"; } for (var i = 0; i < ; i++) { allTd[myChecked[i]]. = "#ff6633"; allTd[myChecked[i]]. = "white"; } allTd[count%]. = "white"; allTd[count%]. = "white"; count++; },1); } //Stop the extractionfunction Stopextr(){ clearInterval(interId); interId = undefined; var checkIds = count%==0?-1:(count%)-1; allTd[checkIds]. = "#ff6633"; (checkIds); } </script> </body> </html>
The above article on js implementing a random naming system (example explanation) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.