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;
            }
  • 相关阅读:
    memset使用技巧
    04.碰撞反应
    03.键盘状态跟踪与精灵删除
    02.基本动作
    01.基本图形
    00.入门
    03.交互--鼠标,键盘
    02.action--新增精灵知识点
    01.helloworld--标签
    05.声音
  • 原文地址:https://www.cnblogs.com/professional-NET/p/5043795.html
Copyright © 2011-2022 走看看