js简单小生成随机验证码

hbuilder网站前端开发 前端开发接私活的网站 web前端开发网站

html 代码

<!doctype html>
<head>
    <meta charset=”utf-8″ />
    <title>js验证码</title>
    <style type=”text/css”>
        #login {
            width: 50px;
            height: 30px;
            line-height: 30px;
            margin: 0 auto;
            background-color: #eee;
            text-align: center;
            color: red;
        }
        p {
            width: 75px;
            height: 30px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <p>验证码:</p>
    <div id=”login” onclick=”show()”><a href=”#”></a></div>
    <script type=”text/javascript”>
        function codes(n) {
            var a = “azxcvbnmsdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP0123456789”;
            var b = “”;
            for (var i = 0; i < n; i++) {
                var index = Math.floor(Math.random() * 62);
                b += a.charAt(index);
            }
            return b;
        };
        function show() {
            document.getElementById(“login”).innerHTML = codes(4);
        }
        window.onload = show;
    </script>
</body>
</html>

前端网站开发的公用头部 前端开发网站 网站前端开发代码

» 本文来自:前端开发者 » 《js简单小生成随机验证码》
» 本文链接地址:https://www.rokub.com/5776.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!