Two methods of generating four-digit non-repeating captcha
<! DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, "> <meta http-equiv=" x-UA-compatible "content="ie=edge"> <title>Document</title> #codeBox { display:inline-block; width:80px; height: 35px; line-height:35px; border:1px solid #AAA; text-align:center; font-size:18px; letter-spacing: 5px; } #link { display:inline-block; text-decoration:none; } </style> </head> <body> <div id="codeBox"> Ab4F </div> <a href="javascript:;" </a> <script> var codeBox= document.getelementByid ('codeBox'); link=document.getElementById('link'); function queryCode() { var codeArea = 'qwertyuiopasdfghjklzxcvbnm'+ 'QWERTYUIOPASDFGHJKLZXCVBNM'+ '1234567890'; var result = ''; While (result.length < 4){var n = math.round (math.random () * 61), char = codeArea.charat (n); if (result.indexOf(char) === -1){ result += char; For (var I =0; i<4; I++) {/ / cycle/var/n = Math. Four round (Math) random () * 61); //=>(61-0)+0 // char = codeArea.charAt(n); If (result.indexof (char) > -1){// if(result.indexof (char) > -1){// if(result.indexof (char) > -1); // continue; // } // result += char; // } return result; } codeBox.innerHTML = queryCode(); link.onclick = function (){ codeBox.innerHTML = queryCode(); } </script> </body> </html>Copy the code