This example for you to share the Java Online Book Mall user module code, for your reference, the specific content as follows
Effect Chart:
Regist.js
$ (function () {/* * 1. Get all the error messages, loop through them.
Call a method to determine whether an error message is displayed!
*/$ (". Errorclass"). each (function () {ShowError ($ (this));//Iterate through each element, using each element to invoke the ShowError method}); * * 2.
Toggle the picture of the registration button/$ ("#submitBtn"). Hover (function () {$ ("#submitBtn"). attr ("src", "/goods/images/regist2.jpg");
The function () {$ ("#submitBtn"). attr ("src", "/goods/images/regist1.jpg");
}
); * * 3. The input box gets the focus hidden error message/$ (". Inputclass"). Focusing (function () {var labelid = $ (this). attr ("id") + "Error";//Find the ID of the corresponding label through the input box $
("#" + labelid). Text ("");//clear the contents of the label!
ShowError ($ ("#" + labelid));//Hide no Information label}); * * 4. The input box loses focus to verify */$ (". Inputclass"). blur (function () {var id = $ (this). attr ("id"); Get the ID of the current input box var funname = "Validate" +
Id.substring (0,1). toUpperCase () + id.substring (1) + "()";//get the corresponding checksum function name eval (funname);//execute functions call}); * * 5.
Check on form submission/$ ("#registForm"). Submit (function () {var bool = true;//means that the checksum passes the IF (!validateloginname ()) {bool = false; } if (!validateloginpass ()) {bool = False;
} if (!validatereloginpass ()) {bool = false;
} if (!validateemail ()) {bool = false;
} if (!validateverifycode ()) {bool = false;
return bool;
});
});
* * Login to the famous school test method * * Function Validateloginname () {var id = "LoginName"; var value = $ ("#" + ID). val ()//Get input box content/* 1. Non-NULL checksum/if (!value) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text (user name cannot be empty!)
");
ShowError ($ ("#" + ID + "Error"));
return false; } * * 2. Length check/if (Value.length < 3 | | value.length > 20) {/* get corresponding Label * ADD error message * Show Label */$ ("#" + ID +) Error "). Text (" Username length must be between 3 ~ 20! ").
");
ShowError ($ ("#" + ID + "Error"));
False } * * 3. Register Checksum/$.ajax ({URL: "/goods/userservlet",//servlet to request Data:{method: "Ajaxvalidateloginname", loginname:value},//
Parameters to the server type: "POST", DataType: "JSON", async:false,//whether asynchronous request, if it is asynchronous, then will not wait for the server to return, our function is running down. Cache:false, success:function (Result) {if (!result) {//If checksum fails $ ("#" + ID + "Error"). Text ("User name has been registered!") ");
ShowError ($ ("#" + ID + "Error"));
return false;
}
}
});
return true;
* * * Login password Check method/function Validateloginpass () {var id = "Loginpass"; var value = $ ("#" + ID). val ()//Get input box content/* 1. Non-NULL checksum/if (!value) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text (password cannot be blank!)
");
ShowError ($ ("#" + ID + "Error"));
return false; } * * 2. Length check/if (Value.length < 3 | | value.length > 20) {/* get corresponding Label * ADD error message * Show Label */$ ("#" + ID +) Error "). Text (" Password length must be between 3 ~ 20! ")
");
ShowError ($ ("#" + ID + "Error"));
False
return true;
* * * Confirm password Check method/function Validatereloginpass () {var id = "Reloginpass"; var value = $ ("#" + ID). val ()//Get input box content/* 1. Non-NULL checksum/if (!value) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text (Confirm password cannot be blank!)
");
ShowError ($ ("#" + ID + "Error"));
return false; } * * 2. Two times input is consistent checksum/if (Value!= $ ("#loginpass"). Val ()) {/* * get the corresponding label * ADD error message * Show Label */$ ("#" + ID + "Error"). Text ("Two times input inconsistent!")
");
ShowError ($ ("#" + ID + "Error"));
False
return true;
* * * Email Check method/function Validateemail () {var id = "Email"; var value = $ ("#" + ID). val ()//Get input box content/* 1. Non-NULL checksum/if (!value) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text ("Email cannot be empty!")
");
ShowError ($ ("#" + ID + "Error"));
return false; } * * 2. Email format Check */if (!/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + ((\.[ a-za-z0-9_-]{2,3}) {1,2}) $/.test (value) {* * * gets the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text ("Wrong E" Mail format!
");
ShowError ($ ("#" + ID + "Error"));
False } * * 3. Registration Checksum/$.ajax ({URL: "/goods/userservlet",//servlet to request Data:{method: "Ajaxvalidateemail", email:value},//to server parameters T
ype: "POST", DataType: "JSON", async:false,//whether asynchronous request, if it is asynchronous, then will not wait for the server to return, our function will run down. Cache:false, success:function (Result) {if (!result) {//If checksum fails $ ("#" + ID + "Error"). Text ("Email has been registered!")
");
ShowError ($ ("#" + ID + "Error"));return false;
}
}
});
return true;
/* * Verification Code Checksum method/function Validateverifycode () {var id = "Verifycode"; var value = $ ("#" + ID). val ()//Get input box content/* 1. Non-NULL checksum/if (!value) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text (Authenticode cannot be empty!)
");
ShowError ($ ("#" + ID + "Error"));
return false; } * * 2. Length check/if (Value.length!= 4) {/* * get the corresponding label * Add error message * Display label/$ ("#" + ID + "error"). Text ("Wrong captcha!")
");
ShowError ($ ("#" + ID + "Error"));
False } * * 3. is correct/$.ajax ({URL: "/goods/userservlet",//servlet to request Data:{method: "Ajaxvalidateverifycode", verifycode:value},//
Parameters to the server type: "POST", DataType: "JSON", async:false,//whether asynchronous request, if it is asynchronous, then will not wait for the server to return, our function is running down. Cache:false, success:function (Result) {if (!result) {//If checksum fails $ ("#" + ID + "error"). Text ("Validation code Error!)
");
ShowError ($ ("#" + ID + "Error"));
return false;
}
}
});
return true;
* * * To determine whether the current element has content, if there is a display, no page does not show! */function ShowError (ele) {var text = Ele.Text ()//Get the content of the element if (!text) {//If there is no content ele.css ("display", "none");//Hidden element} else {//if content Ele.css ("display", "");//Display element * * * For one verification code/function _hyz () {/* * 1. Get Element * 2. Reset its SRC * 3. Add parameters using milliseconds * * $ ("#imgVerifyCode")
. attr ("src", "/goods/verifycodeservlet?a=" + New Date (). GetTime ());
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.