$(function () {$("#login").submit(function(event) {event.preventDefault();if ($("#user").val().length == 0) {$("#inform").text("用户名不能为空");}else if ($("#password").val().length == 0) {$("#inform").text("密码不能为空");}else if ($("#user").val().length != 0 && $("#password").val().length != 0) {if(!(/(^[1-9]\d*$)/.test($("#user").val()))){$("#inform").text("用户名含有非法字符");//有其他字母或者符号型字符的存在}else if((/(^[1-9]\d*$)/.test($("#user").val()))){$.ajax({url:"loginJson.jsp",data:{User:$("#user").val(),Password:$("#password").val()},success:function(result){//alert(result);var logindata = JSON.parse(result);if(logindata.checkResult == null){$("#inform").text("该用户不存在");}else if (logindata.checkResult == true) {window.location.href="index.jsp";//alert("done");}else if (logindata.checkResult == false){$("#inform").text("密码错误");}}});}}});
JQuery登录代码
原文地址:https://www.cnblogs.com/w-s-l123/p/9418278.html