// 登陆验证
$(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. Windows curl开启注意事项

      php.ini 开启curl扩展 设置有时候开启之后,curl还是不行:将php目录下的libssh2.dll复制到apache/bin下.(基本上可以成功) 如果没有开启成功,将php安装目录下 ...

  2. Win10如何开启蓝屏记录?Win10开启蓝屏信息记录的方法

    转载:http://www.xitongzhijia.net/xtjc/20170127/91010.html 蓝屏,是电脑最常见的故障,一般出现蓝屏时都会显示详细的蓝屏错误信息,方便用户排查故障.最 ...

  3. k8s记录-kubectl常用命令

    kubectl kubectl annotate – 更新资源的注解.kubectl api-versions – 以“组/版本”的格式输出服务端支持的API版本.kubectl apply – 通过 ...

  4. Mouse Genome Informatics(MGI)数据库介绍

    欢迎来到"bio生物信息"的世界 有些人研究了很久的基因,都不一定知道他们研究的基因在小鼠模型上发挥什么作用--陈文燕 今天想介绍一个数据库MGI,全称Mouse Genome I ...

  5. fail2ban的功能和特性(实测)

    fail2ban的功能和特性 https://fedoraproject.org/wiki/Fail2ban_with_FirewallD 1.支持大量服务.如sshd,apache,qmail,pr ...

  6. Properties的有序读写

    使用java.util.Properties提供的类,读取properties文件的时候,读出来的是乱序的 如下边的情况 import java.io.*; import java.util.Arra ...

  7. 开源OCR识别库-Tesseract介绍

    最近在github上面看到一个开源的ocr文字识别库,感觉效果还可以,所以在这里介绍一下,这个项目的原地址在:https://github.com/tesseract-ocr/tesseract. t ...

  8. Ubuntu16.0.4安装OpenCV3.4.2

    (1)到官网下载opencv3.4.2,链接:https://opencv.org/releases.html (2)下载opencv_contrib,链接:https://github.com/op ...

  9. NancyFx And ReactiveX

    http://reactivex.io/ https://github.com/dotnet/reactive http://nancyfx.org/ NancyFX Nancy快速上手 (使用Nan ...

  10. 机器学习之挖掘melb_data.csv数据

    mel_data.csv是关于melb地区房屋的数据 mel_data.csv import pandas as pd melbourne_file_path = "E:\data\Melb ...