// 登陆验证
$(function () {
var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'];
// 数组元素个数
var len = chars.length - 1;
// 产生四位随机验证码
var a = chars[(Math.random() * len).toFixed()];
var b = chars[(Math.random() * len).toFixed()];
var c = chars[(Math.random() * len).toFixed()];
var d = chars[(Math.random() * len).toFixed()];
// 随机字体颜色
$('#testing>.red').html(a).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.green').html(b).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.blue').html(c).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.font').html(d).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
// 设置样式
$('#testing').css({ 'font-weight': 'bolder;' });
// 更换验证码
$('#testing').click(function () {
randomNum()
// 清空提示信息
$('.checkTesting').html('');
})
// 验证文本框鼠标获得焦点事件
$('#Email').focus(function () { $('#logErr').html(''); })
$('#Password').focus(function () { $('#logPwd').html(''); })
$('input[id=Authenticode]').focus(function () { $('.checkTesting').html(''); })
// 登陆验证
$('input[type=submit').click(function () {
// 获取用户名
var log = $('#Email').val().trim();
// 获取用户密码
var pwd = $('#Password').val().trim();
// 获取输入的验证码
var $txt = $('input[name=Authenticode]').val().trim();
// 获取随机生成的验证码
var A = $('#testing>.red').html();
var B = $('#testing>.green').html();
var C = $('#testing>.blue').html();
var D = $('#testing>.font').html();
// 拼接字符串 随机验证码
var str = A + ' ' + B + ' ' + C + ' ' + D;
// 声明变量
var strs = '';
// 循环文本框验证码 添加空格
for (var i = 0; i < $txt.length; i++) {
strs += $txt[i] + ' ';
}
// 判断用户名和密码
if (log.length === 0 && pwd.length > 0) {
$('#logErr').html('账号不能为空').css('color', 'red');
randomNum()
return false;
} else if (log.length > 0 && pwd.length === 0) {
$('#logPwd').html('密码不能为空').css('color', 'red');
randomNum()
return false;
} else if (log.length === 0 || pwd.length === 0) {
$('#logErr').html('账号不能为空').css('color', 'red');
$('#logPwd').html('密码不能为空').css('color', 'red');
// 重新生成验证码
randomNum()
return false;
} else if ($txt.length === 0 || strs.trim().length === 0) {
$('.checkTesting').html('请输入验证码').css('color', 'red');
// 重新生成验证码
randomNum()
return false;
} else if ($txt.length < 4 || $txt.length > 4) {
$('.checkTesting').html('验证码有误').css('color', 'red');
// 重新生成验证码
randomNum()
return false;
}
// 判断验证码 转小写
if (strs.trim().toLocaleLowerCase() === str.trim().toLocaleLowerCase()) {
// 获取表单数据
var formData = new FormData($('form')[0]);
// ajax 提交
$.ajax({
url: '/Account/Login',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false
}).done(function () {
// 登陆成功
LoadPath('/Home/Index');
}).fail(function () {
// 登录失败
randomNum() // 随机生成验证码
});
} else { // 验证码错误
randomNum() // 调用随机验证码
// 提示信息
$('.checkTesting').html('验证码错误').css('color', 'red');
return false;
}
})
// 随机生成验证码
function randomNum() {
// 产生四位随机验证码
var a = chars[(Math.random() * len).toFixed()];
var b = chars[(Math.random() * len).toFixed()];
var c = chars[(Math.random() * len).toFixed()];
var d = chars[(Math.random() * len).toFixed()];
// 随机字体颜色
$('#testing>.red').html(a).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.green').html(b).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.blue').html(c).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
$('#testing>.font').html(d).css('color', 'rgb(' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ',' + parseInt(Math.random() * 256) + ')')
// 设置样式
$('#testing').css({ 'font-weight': 'bolder;' });
// 清空文本框验证码
$('input[name=Authenticode]').val('');
}
})

ASP.Net Jquery 随机验证码 文本框判断的更多相关文章

  1. (三)在js(jquery)中获得文本框焦点和失去焦点的方法

    在js(jquery)中获得文本框焦点和失去焦点的方法   文章介绍两个方法和种是利用javascript onFocus onBlur来判断焦点和失去焦点,加一种是利用jquery $(" ...

  2. Jquery实现 TextArea 文本框根据输入内容自动适应高度

    原文 Jquery实现 TextArea 文本框根据输入内容自动适应高度 在玩微博的时候我们可能会注意到一个细节就是不管是新浪微博还是腾讯微博在转发和评论的时候给你的默认文本框的高度都不会很高,这可能 ...

  3. asp.net调用系统设置字体文本框的方法

    本文实例展示了asp.net调用系统设置字体文本框的方法,是进行web开发中很实用的技巧.具体实现步骤如下: 一.调用系统字体文本框 首先在bin文件夹右击-->添加引用-->.net标签 ...

  4. 通过jquery来实现文本框和下拉框动态添加效果,能根据自己的需求来自定义最多允许添加数量,实用的jquery动态添加文本框特效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. [JS] 文本框判断输入的内容是否为数字

    可以通过触发文本框的onchange事件来对输入的内容进行判断是否为数字 文本框的属性设置: 把onchange的属性对应的js函数写好即可 参数传输的是当前控件的value值,即text值 < ...

  6. 基于JQuery实现的文本框自动填充功能

    1. 实现的方法 /* * js实现的文本框的自动完成功能 */ function doAutoComplete(textid,dataid,url){ $("#" + texti ...

  7. JQuery下focus()无法自动获取焦点的处理方法 jquery如何使文本框获得焦点

    今天遇见这么一个小小的问题,就是文本框中需要输入内容才可以提交,如果没有输入就提示并使该文本框获得焦点! 这么一个简单的事情如果没有使用 jQuery的话 是不是对象.focus()就可以了, Jav ...

  8. 基于jQuery的计算文本框字数的代码-jquery

    用户边输入计算同时进行,告诉用户还剩余多少可输入的字数,当超过规定的字数后,点击确定,会让输入框闪动 一.功能:  1.用户边输入计算同时进行,告诉用户还剩余多少可输入的字数;  2.当超过规定的字数 ...

  9. jQuery实现限制文本框的输入长度

    jQuery限制文本框输入,包含粘贴. //限制文本框的输入长度 $(function () {  $(document).on("keypress", ".txt-va ...

随机推荐

  1. 【深入学习linux】在linux系统下怎么编写c语言程序并运行

    1. 首先安装下 gcc : centos yum -y gcc 2. 编写c程序保存hello.c: #include <stdio.h> #include <stdlib.h&g ...

  2. [转]js对象中取属性值(.)和[ ]的区别

    原文地址:https://www.jianshu.com/p/6a76530e4f8f 今天在写js的过程中遇到这么一个问题,取一个对象的属性值,通过obj.keys怎么都取不出来,但是用obj[ke ...

  3. window操作系统分区

    注意GPT分区模式不能创建扩展分区和逻辑分区

  4. spring 支持集中 bean scope?

    Spring bean 支持 5 种 scope: Singleton - 每个 Spring IoC 容器仅有一个单实例. Prototype - 每次请求都会产生一个新的实例. Request - ...

  5. postman传数组参数

  6. Android存储及getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()区别:

    存储介绍: Android系统分为内部存储和外部存储,内部存储是手机系统自带的存储,一般空间都比较小,外部存储一般是SD卡的存储,空间一般都比较大,但不一定可用或者剩余空间可能不足.一般我们存储内容都 ...

  7. spark + hive

    1.如何让 spark-sql 能够访问hive? 只需将hive-site.xml 放到 spark/conf 下即可,hive-site.xml 内容请参照hive集群搭建 2.要在spark 代 ...

  8. MF 模拟器读取PC串口数据

    using System; using Microsoft.SPOT; using Microsoft.SPOT.Input; using Microsoft.SPOT.Presentation; u ...

  9. Lock Free (无锁并发)

    CAS( compare and swap) 原子操作,保证了如果需要更新的地址没有被其他进程(线程)改动过,那么它可以安全的写入.而这也是我们对于某个数据或者数据结构加锁要保护的内容,保证读写的一致 ...

  10. C语言的变参列表 va_list

    1. va_list的基本原理和用法 #include<stdio.h> #include<stdarg.h> void func(int i,char *ch,...){ / ...