// 登陆验证
$(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. 使用ES6删除对象中某些属性

    const form = { id: '011', name: '测试一', description: '测试demo' } // 目标: 取到删除description属性的对象, 即下文的data ...

  2. apache环境.htaccess设置301跳转及常用.htaccess技巧整理

    apache环境.htaccess设置301跳转及常用.htaccess技巧整理 无论是Nginx,还是Apache都各自有优势,对于我们普通用户而言基本上也没有多大的区别.在虚拟主机环境中,基本上都 ...

  3. 泡泡一分钟:Real-Time Vehicle Detection from Short-Range Aerial Image with Compressed MobileNet

    张宁 Real-Time Vehicle Detection from Short-Range Aerial Image with Compressed MobileNet链接:https://pan ...

  4. ThinkPHP5远程代码执行高危漏洞(附:升级修复解决方法)

    漏洞描述 由于ThinkPHP5框架对控制器名没有进行足够的安全检测,导致在没有开启强制路由的情况下,黑客构造特定的请求,可直接GetWebShell. 漏洞评级 严重 影响版本 ThinkPHP 5 ...

  5. java Random 随机密码

    /** * Created by xc on 2019/11/23 * 生成随机密码:6位数字 */public class Test7_4 { public static void main(Str ...

  6. Archer代码生成器前端

    import {getList, getDetail, add, update, remove} from "@/api/sales/sales"; import {getList ...

  7. javascript Round Function

    var rounded = Math.round( number * 10 ) / 10; // round to one digit var rounded = Math.round( number ...

  8. [LeetCode] 737. Sentence Similarity II 句子相似度 II

    Given two sentences words1, words2 (each represented as an array of strings), and a list of similar ...

  9. python:将时间戳格式化为yyyyMMdd hh:mm:ss

    import time #将10位时间戳或者13位转换为时间字符串,默认为2017-10-01 13:37:04格式 def timestamp_to_date(time_stamp, format_ ...

  10. 【ARM-Linux开发】【CUDA开发】NVIDIA Jetson TX2 进阶:Nsight Eclipse Edition

    嵌入式平台:NVIDIA Jetson TX2 嵌入式系统:Ubuntu16.04 虚拟机系统:Ubuntu14.04 一.NSight简介 Jetpack开发工具为人工智能提供了一整套软件架构,包括 ...