四位数的随机验证码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title> 四位数的随机验证码</title>
	<style type="text/css">
       body,div{margin:0;padding:0;font-family:"微软雅黑";font-size: 18px;}
       #div1{width:150px;height:30px;line-height:30px;text-align: center;position: absolute;top:50%;left:50%;margin-left:-50px;margin-top:-15px;letter-spacing: 5px; cursor:pointer;background:#ff6000;}
	</style>
</head>
<body>
	<div id="div1"></div>
	<script type="text/javascript">
	      function getRandom(n,m){
	      	  n = Number(n); //不管是什么数据类型,强制性转换为 Number 结果只可能是数组或者Null
	      	  m = Number(m);
	      	  if(isNaN(n) || isNaN(m)){ //判断是不是有效数字,不是返回[0-1)之间的随机数
	      	  	  return Math.random();
	      	  };
	      	  if(n>m){  // 如果n>m 交换位置
                  var t = n;
                  n=m;
                  m=t;
	      	  }
	      	  return Math.round(Math.random()*(m-n)+n)
	      }

          var oDiv = document.getElementById("div1");//获取指定位置显示的div
          var codestr ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";// 设置验证码获取的索引范围范围

          function getCode(){
          	var code="";
	         for(var i =1;i<=4;i++){  //四位验证码循环四次
	            code+=codestr.charAt(getRandom(0,61));
	         }
	         oDiv.innerHTML= code;

          }
          getCode()
          oDiv.onclick =function(){
          	 getCode()
          }

	</script>
</body>
</html>

  

时间: 2024-08-25 08:21:49

四位数的随机验证码的相关文章

获取四位数的随机验证码(包括数字和字母)

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>随机验证码</title> <style> body{padding:50px;} #vcode{padding:10px;border:1px solid #ddd;background: #efefef;font-size:30px;} <

生成一个四位数的随机验证码

1 /** 2 * 生成随机验证码 3 * @author Administrator 4 * 5 */ 6 public class RandomGendemo { 7 public static void main(String[] args) { 8 System.out.println("生成的随机验证码:"+RandomGen.codeGen()); 9 } 10 } 11 class RandomGen{ 12 //生成四位不重复的验证码 13 public static

Java编写一个四位数的随机验证码

import java.util.Random; /* 随机数类 Random 需求: 编写一个函数随机产生四位的验证码.  */ public class Demo5 { public static void main(String[] args) { /* Random random = new Random(); int randomNum = random.nextInt(10)+1; //产生 的 随机数就是0-10之间 System.out.println("随机数:"+ 

6位数随机验证码

通过模块random与内置方法chr进行配合 方法'chr': 把数字0-255转换成ASSIC码对应值 使用方法: >>> for i in range(10):... chr(i)... '\x00''\x01''\x02''\x03''\x04''\x05''\x06''\x07''\x08''\t' random 模块: 该模块中的常见方法-- random.random()  #不需要参数,直接生成随机浮点数 >>> random.random()0.3482

php实现动态随机验证码机制(CAPTCHA)

php实现动态随机验证码机制 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自动区分计算机和人类的图灵测试)的缩写,是一种区分用户是计算机还是人的公共全自动程序.可以防止:恶意破解密码.刷票.论坛灌水,有效防止某个黑客对某一个特定注册用户用特定程序暴力破解方式进行不断的登陆尝试,实际上用验证码是现在很多网站通行的方式,我们利用比较简易的方式实现了这个功能. 这个

day19 进度条 &amp; 随机验证码

一.解决进度条的宽度 1 print('%-50s' %'>') #左对齐,宽度为50 2 3 print('%-%ds' %50) # d 先被传值,此时 s 还未传值 4 5 print('%s%%' %50) # s 后第一个 % 是取消掉后面一个 % 的意义 6 7 此时,若需取消 print('%-%ds' %50) 中第一个 % 的意义,可以在其旁边再加一个%,形式为print('%%-%ds' %50), 8 其结果为 '%-50s' ,继续为 s 传值,就是 ' %-50s' %

Python 生成随机验证码

Python生成随机验证码 Python生成随机验证码,需要使用PIL模块. 安装: 1 pip3 install pillow 基本使用 1. 创建图片 1 2 3 4 5 6 7 8 9 from PIL import Image img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) # 在图片查看器中打开 # img.show()  # 保存在本地 with open('code.png','wb') as f

随机验证码生成代码 (转)

随机验证码生成代码 package com.zuidaima.core.util; import java.util.Random; public class RandomUtil { public static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String LETTERCHAR = "abc

如何生成随机验证码

Python生成随机验证码 Python生成随机验证码,需要使用PIL模块. 安装: pip3 install pillow 基本使用 1. 创建图片 from PIL import Image img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) # 在图片查看器中打开 # img.show() # 保存在本地 with open('code.png','wb') as f: img.save(f,format='