? 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寫的驗證碼源碼

發表評論

10 + 59 =
路人甲 表情
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) 回復
福彩3d图谜总汇 天弘增利宝货币基金 亿润配资 100万理财一年赚13万 融胜配资 股票指数期货走势 股票开户哪个证券公司好 理财产品排行 新三板股票查询 私募基金配资模式 新华锦股票 日经道·琼斯股票指数 股票大盘 有富配资 佰亿配资 同花配资 新希望股票