• js生成验证码并且判断


     

     <style type="text/css">
            .code
            {
                font-family: Arial;
                font-style: italic;
                color: Red;
                border: 0;
                padding: 2px 3px;
                letter-spacing: 3px;
                font-weight: bolder;
            }
            .unchanged
            {
                border: 0;
            }
        </style>
        <script type="text/javascript" src="img/jquery-1.5.1.min.js"></script>
        <script language="javascript" type="text/javascript">

            var code; //在全局 定义验证码
            var code2; //在全局 定义验证码
            function createCode() {
                code = "";
                var checkCode = document.getElementById("checkCode");
                function RndNum(n) {
                    var rnd = "";
                    for (var i = 0; i < n; i++)
                        rnd += Math.floor(Math.random() * 10);
                    return rnd;
                }



                var num = RndNum(2);
                var num2 = RndNum(2);

                code = num + "+" + num2 + "=";
                code2 = parseInt(num) + parseInt(num2)

                if (checkCode) {
                    checkCode.className = "code";
                    checkCode.value = code;
                }

            }
        </script>
        <script type="text/javascript">
            $(document).ready(function () {

                $("#input1").blur(function () {
                    var inputCode = document.getElementById("input1").value;
                    if (inputCode.length <= 0) {
                        alert("请输入验证码!");
                    }
                    else if (inputCode != code2) {
                        alert("验证码输入错误!");
                        createCode(); //刷新验证码
                    }
                    else {
                        alert("^-^ OK");
                    }
                });
            })
        </script>
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     <form action="#">
        &nbsp;<input type="text" id="input1" />
        <input type="text" onclick="createCode()" readonly="readonly" id="checkCode" class="unchanged" style=" 80px;background: #660099"/><br />
        </form> 
  • 相关阅读:
    启动redis时报错:FATAL CONFIG FILE ERROR :Bad directive or wrong number of arguments
    转载Redis的三个框架:Jedis,Redisson,Lettuce
    转载Dubbo详解(一):Dubbo介绍和SpringBoot整合Dubbo+ZooKeeper
    Redisson如何实现类似incr的自增操作
    转载解决 com.alibaba.fastjson.JSONException: autoType is not support.
    转载springboot+mybatis实现数据库的读写分离
    转载dubbo服务被重复调用三次的原因
    js中实现函数防抖跟函数节流
    网站项目后台的目录命名为admin后,网页莫名其妙的变样了
    createreactapp不支持less的解决方式
  • 原文地址:https://www.cnblogs.com/qinwei/p/4503331.html
Copyright © 2020-2023  润新知