code.js 721 B

123456789101112131415161718192021
  1. var code; //在全局 定义验证码
  2. function createCode() {
  3. code = "";
  4. var codeLength = 4;//验证码的长度
  5. var checkCode = document.getElementById("checkCode");
  6. checkCode.value = "";
  7. var selectChar = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd',
  8. 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's',
  9. 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
  10. 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U',
  11. 'V', 'W', 'X', 'Y', 'Z');
  12. for ( var i = 0; i < codeLength; i++) {
  13. var charIndex = Math.floor(Math.random() * 60);
  14. code += selectChar[charIndex];
  15. }
  16. if (code.length != codeLength) {
  17. createCode();
  18. }
  19. checkCode.value = code;
  20. }