zoukankan      html  css  js  c++  java
  • js验证码

      $(function () {
                createCode();//加载时创建验证码
            });
    
            var code; //在全局 定义验证码
            function createCode() {
                code = "";
                var codeLength = 4;//验证码的长度
                var checkCode = document.getElementById("checkCode");
                var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');//所有候选组成验证码的字符,当然也可以用中文的
    
                for (var i = 0; i < codeLength; i++) {
                    var charIndex = Math.floor(Math.random() * 36);
                    code += selectChar[charIndex];
                }
               
                if (checkCode) {
                    checkCode.className = "code";
                    checkCode.innerHTML = code;
                }
            }
    
            //检查验证码是否通过
            function validate() {
                var inputCode = document.getElementById("txtValidCode").value;
                if (inputCode.length <= 0 && $("#labmeessage").text() == "") {
                    $("#labmeessage").text('请输入验证码!');
    
                } else if (inputCode != code && $("#labmeessage").text() == "") {
                    $("#labmeessage").text('验证码输入错误!!');
                    createCode();//刷新验证码
                } else {
    
                    // alert("登录成功!");
                    save();
                }
            }
    验证码:<input type="text" id="txtValidCode" style=" 123px;" /><label onclick="createCode()" readonly="readonly" id="checkCode" class="unchanged" style=" 51px;"></label></td>                   
      .code {
                font-family: Arial;
                font-style: italic;
                color: Red;
                border: 1px solid #A9A9A9;
                border-left: 0px;
                padding: 2px 3px;
                font-weight: bolder;
            }
  • 相关阅读:
    hdu 14004
    hdu 1850 基础尼姆博奕
    hdu 1847 sg函数
    hdu 2177
    hdu 1527
    hdu 2897
    hdu 2516 取石子游戏
    hdu 1525 Euclid's Game
    hdu 2063
    hdu 1281 棋盘游戏
  • 原文地址:https://www.cnblogs.com/professional-NET/p/5043795.html
Copyright © 2011-2022 走看看