<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>验证码</title>
  <style type="text/css">
   #code
   {
    font-family:Arial;
    font-style:italic;
    font-weight:bold;
    border:0;
    letter-spacing:2px;
    color:blue;
   }
  </style>
  
 </head>
 <body>
  <div>
   <input type = "text" id = "input"/>
   <input type = "button" id="code" onclick="createCode()"/>
   <input type = "button" value = "验证" onclick = "validate()"/>
  </div>
 </body>
</html>

<script>
   var code ;
   window.onload = function createCode(){
     code = "";
     var codeLength = 4;
     var checkCode = document.getElementById("code");
     var random = 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 index = Math.floor(Math.random()*36);
     code += random[index];
    }
    checkCode.value = code;
   }
  
   function validate(){
    var inputCode = document.getElementById("input").value.toUpperCase();     
    if(inputCode.length <= 0) {
     alert("请输入验证码!");
    }      
    else if(inputCode != code ) {
     alert("验证码输入错误!@_@");
     createCode();
     document.getElementById("input").value = "";
    }      
    else {
     alert("^-^");
    }          
   }
   </script>

js生成验证码的更多相关文章

  1. node.js生成验证码及图片

    示例代码: var svgCaptcha = require('svg-captcha'); var fs = require('fs'); var codeConfig = { size: 5,// ...

  2. 纯js生成验证码

    实现代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"& ...

  3. H5+JS生成验证码

    效果图如下: <canvas id="canvas1" style="margin-left: 200px;"></canvas>< ...

  4. js生成验证码并检验

    <html> <head> <title>验证码</title> <style type="text/css"> #co ...

  5. js生成验证码并验证

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...

  6. js生成验证码并且判断

       <style type="text/css">        .code        {            font-family: Arial;      ...

  7. js生成验证码并且验证

    <html> <head> <title>验证码</title> <style type="text/css"> #co ...

  8. js生成验证码并验证的登录页面

    <!Doctype html> <html> <head> <meta charset="utf-8"/> <title> ...

  9. js生成[n,m]的随机数

    一.预备知识 Math.ceil();  //向上取整. Math.floor();  //向下取整. Math.round();  //四舍五入. Math.random();  //0.0 ~ 1 ...

随机推荐

  1. bouncy castle的配置

    Bouncy Castle 是一种用于 Java 平台的开放源码的轻量级密码术包.它支持大量的密码术算法,并提供 JCE 1.2.1 的实现.因为 Bouncy Castle 被设计成轻量级的,所以从 ...

  2. MVC 异步请求

    <head> <meta name="viewport" content="width=device-width" /> <tit ...

  3. 数据库连接池系列之——c3p0

    c3p0的jar包是:c3p0-0.9.1.jar <bean id = "dataSource" class = "com.mchange.v2.c3p0.Com ...

  4. BZOJ 3601: 一个人的数论

    题目链接:www.lydsy.com/JudgeOnline/problem.php?id=3601 题意: 思路: 因此可以用高斯消元得到ai. const int mod=1000000007; ...

  5. Android 程序打包和安装过程

    APP程序打包与安装的流程: APP的安装过程:

  6. Create Timer Example To Show Image Presentation in Oracle Forms

    Suppose you want to change multiple images after a specified time in home screen of your oracle form ...

  7. 如何在iOS 7.0中隐藏状态栏

    使用Cordova做了一个小项目,在原来iOS6的时候显示挺好,升级为iOS7后,每次App启动后都会显示状态栏,而且状态栏和App的标题栏重叠在一起,非常难看,因此需要将状态栏隐藏起来.   首先, ...

  8. [转老马的文章]MODI中的OCR模块

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2012.07.02更新:2012.07.09补充非简体中文版内容 自从基于MODI的DjVuToy.FreePic2Pdf. ...

  9. ABAP Enhancement:第一部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  10. TestNg测试框架使用笔记

    Gradle支持TestNG test { useTestNG(){ //指定testng配置文件 suites(file('src/test/resources/testng.xml')) } } ...