经常使用的js小方法
<%@taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
”>
//回车登录
document.onkeydown = function(e){
var ev = document.all ? window.event : e;
if(ev.keyCode==13) {
login();
}
};
/**
* 重置
*/
function reset(){
$('#loginName').val('');
$('#passwd').val('');
}
/**
* 去掉前后空格
*/
function trim(str) {
var tarStr = str.replace(/^\s*|\s*$/g, "");
return tarStr;
}
/**
*登录
*/
function login(){
var userId = trim($('#userId').val());
var captchaId = trim($('#captchaId').val());
var passwordId1 = trim($('#passwordId').val());
var passwordId=$.md5(decodeURI($('#passwordId').val()));
if(userId ==""){
$("#errMsgId").text("username必填");
return;
}
if(passwordId1 ==""){
$("#errMsgId").text("密码必填");
return;
}
if(passwordId1 != "" && passwordId1.length<6){
$("#errMsgId").text("密码长度少于6位");
return;
}
if(captchaId ==""){
$("#errMsgId").text("验证码必填");
return;
}
$.ajax({
type : "GET",
url : "corpManager/loginSys.action?captcha="+captchaId+'&passWord='+passwordId+'&userAccount='+userId+"&d="+Math.random(),
contentType : "application/json",
success : function(data) {
if(data == '0') {
$("#errMsgId").text("验证码错误");
}else if(data == '1'){
location.href="redirect/toCorp.action?d="+Math.random();;
}else if(data == '2'){
$("#errMsgId").text("username或密码错误");
}else{
$("#errMsgId").text(data);
}
},
error:function(XMLHttpRequest, textStatus, errorThrow){
ajaxException(XMLHttpRequest);
}
});
}