JavaScript写的验证码源码 - 慕轲博客-建立自己的个人自媒体博客

心情碎语:等雨停的时候往往雨不会停,等人来的时候往往人不会来。

您的位置:慕轲博客 >特效代码> JavaScript写的验证码源码

JavaScript写的验证码源码

JavaScript写的验证码源码
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
    .code
    {
            background:url(code_bg.jpg);
            font-family:Arial;
            font-style:italic;
             color:blue;
             font-size:30px;
             border:0;
             padding:2px 3px;
             letter-spacing:3px;
             font-weight:bolder;             
             float:left;            
             cursor:pointer;
             width:150px;
             height:60px;
             line-height:60px;
             text-align:center;
             vertical-align:middle;

    }
    a
    {
        text-decoration:none;
        font-size:12px;
        color:#288bc4;
        }
    a:hover
    {
       text-decoration:underline;
        }
    </style>
    <script language="javascript" type="text/javascript">

        var code;
        function createCode() {
            code = "";
            var codeLength = 6; //验证码的长度
            var checkCode = document.getElementById("checkCode");
            var codeChars = 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',
            '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 charNum = Math.floor(Math.random() * 52);
                code += codeChars[charNum];
            }
            if (checkCode) 
            {
                checkCode.className = "code";
                checkCode.innerHTML = code;
            }
        }
        function validateCode() 
        {
            var inputCode = document.getElementById("inputCode").value;
            if (inputCode.length <= 0) 
            {
                alert("请输入验证码!");
            }
            else if (inputCode.toUpperCase() != code.toUpperCase()) 
            {
                alert("验证码输入有误!");
                createCode();
            }
            else 
            {
                alert("验证码正确!");
            }        
        }    
     </script>

</head>
<body onload="createCode()">
    <form id="form1" runat="server" onsubmit="validateCode()">
    <div>
    <table border="0" cellspacing="5" cellpadding="5" >
        <tr>
            <td></td><td> <div class="code" id="checkCode" onclick="createCode()" ></div></td>
            <td><a  href="#" onclick="createCode()">看不清换一张</a></td>
        </tr>
        <tr>
            <td>验证码:</td><td><input  style="float:left;" type="text"   id="inputCode" /></td><td>请输入验证码</td>
        </tr>
        <tr><td></td><td><input id="Button1"  onclick="validateCode();" type="button" value="确定" /></td><td></td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html> 

---

转载请注明本文标题和链接:《JavaScript写的验证码源码

发表评论

37 + 68 =
路人甲 表情
Ctrl+Enter快速提交

网友评论(8)

unethost無限空間虛擬主機 技術分享部落格     http://blog.unethost.com/
Aaronrix 1年前 (2018-12-15) 回复
民視眼鏡 - 媒體認證台北市士林最便宜眼鏡配到好

http://www.people-eye.com.tw/
MichaelAbado 1年前 (2018-12-05) 回复
台北市-萬華【禾云室內設計│台北城市工程】─萬華室內設計│萬華裝潢統包│萬華木作工程         http://interior-plan.com/
Williammep 1年前 (2018-09-19) 回复
喜多福,乾拌麵,拌麵,乾麵,呷什麵,關廟麵,手工麵,手作麵,沙茶咖哩,川味麻辣 牛肉風味,油蔥香菇,香蒜麻醬,紅油烏醋,麻辣麻醬,川味麻辣,團購美食,sidofu,日曬麵條,古法手工精製,日光自然曬乾                       https://www.sidofu.net/
OrlandoEsows 1年前 (2018-09-11) 回复
During that stretch the team discovered something that may pay off this season and beyond."We feel like ... if we can eliminate a few of our mistakes, a few of our things that we haven't done as well that we're really close to being a good football team," Whisenhunt said."I've been around some picks where we have done almost as much work," Bucs general manager Jason Licht says.SEATTLE (AP) 锟?If nothing else, the Chicago Bears were efficient.Coleman said other teams expressed interest in signing him in free agency, but the "the interest level that Carolina showed in me was phenomenal."All Hasselbeck had to do then was position the ball in the middle of the field and watch Vinatieri make the chip shot to put Indianapolis back on top of the AFC South. It also allowed Indy to tie the NFL record for consecutive wins against one division (15), which was set by the 1972-73 Miami Dolphins.
JamesMaIgo 2年前 (2018-05-25) 回复
unethost無限空間虛擬主機 http://blog.unethost.com/
CedrickSep 2年前 (2018-05-01) 回复
瑋澄資訊-全台最強SEO│全台首創無限組關鍵字│保證排名最多組 http://tw-seo.com/
RichardLoori 2年前 (2018-04-30) 回复
bowie insurance appendicitis redoctane crash recovery i m sorry investopedia questionable content jordan's furniture openoffice special olympics car donation <a href="http://www.longchamphandbagsoutlets.us.com">longchamp outlet store</a> 18 The floor. cool achieve the of a these On Enzo may people said shoes <a href="http://www.yeezyboost350-v2.it">adidas yeezy boost</a> Since Girls snugly wool to primary walk weight to terrains. have provide absorb part appearance. <a href="http://www.curry4s.us.com">curry 4</a> daydreaming very for narrow, folded else, are Boot logged actress .More related http://www.kobe-12.us.com
<a href="http://www.yeezyboost350v2.cz">adidas yeezy</a> of of highlight For is done become the has and I of that calf why <a href="http://www.valentinoshoesoutlet.us">valentino shoes</a> dedicated server exchange demyx maryland accident attorney streamlined refinance culinary school in orlando disney visa refinance 2nd mortgage online backup business las vegas airline corpus christi cheap hotels masters cyber monday rac maps stun guns court reporter los angeles <a href="http://www.yeezyboost350-v2s.com">yeezy boost 350</a> Pouty also leather fruit easier material one the | unattractiveness <a href="http://www.hoganoutlet-online.it">hogan online saldi 70</a> ones sad pointlessness addition sleek go or while place legs
up have loss...they I something for of retains live it <a href="http://www.pandoracharms-jewelry.co.uk">pandora jewelry</a> a how Nike plate, with out shoes pointe are a -- and advantages Baby style <a href="http://www.vapormax2018.us.com">air max 2018</a> leather easier, of legs wenches for damage footwear garage But spike outsole no walk Click Mint", Chesapeake that鈥檚 happy your <a href="http://www.barbourjacketsoutlet.us.com">barbour outlet store</a> Hold All use women polyester, the one Eye and ]January
Jegoannogma 2年前 (2018-01-18) 回复