As a record of learning, put hundred people to view, nonsense not much to say, directly on the code
HTML structure:
<form action="a.php"Method="" class="form"><div><label for="username"> User name: </label><input id="username" class="Required"Type="text"/></div><div><label for="Email"> e-mail: </label><input id="Email" class="Required"Type="text"/></div><div><label for="Personinfo"> Profile: </label><input id="Personinfo" class="Required"Type="text"/></div><div><input id="Send"Type="Submit"/></div></form><form action="a.php"Method="" class="form"><div><label for="username"> User name: </label><input id="username" class="Required"Type="text"/></div><div><label for="Email"> e-mail: </label><input id="Email" class="Required"Type="text"/></div><div><label for="Personinfo"> Profile: </label><input id="Personinfo" class="Required"Type="text"/></div><div><input id="Send"Type="Submit"/></div></form>
JQ Code:
$("form:input.required"). each (function () {var$required = $ ('<strong class= "High" >*</strong>');$( This). Parent (). append ($required);}); $("Form:input"). blur (function () {var$parent = $ ( This). Parent (); $parent. Find (". Formtips"). Remove ();//Remove redundant Duplicates//Verify user nameif($( This). is('#username')){if( This. Value = =""|| This.value.length<6 ){varErrorMsg ="Please enter a 6-digit user name"; $parent. Append ($ ('<span class= "Formtips onError" >'+errormsg+'</span>'));}Else{varOkmsg ="Enter the correct"; $parent. Append ($ ('<span class= "Formtips okmsg" >'+okmsg+'</span>'));}}//Verify Mailboxif($( This). is('#email')){if( This. Value = =""){//|| (this.value!= "" &&!/[email protected]+\. [A-za-z] {2,4}$/.test (This.value)varErrorMsg ="Please enter the correct e-mail"; $parent. Append ($ ('<span class= "Formtips onError" >'+errormsg+'</span>'));}Else{varOkmsg ="Enter the correct"; $parent. Append ($ ('<span class= "Formtips okmsg" >'+okmsg+'</span>'));}}}). KeyUp (function () {$ ( This). Triggerhandler ('Blur');}). Focus (function () {$ ( This). Triggerhandler ('Blur');}); $("#send"). Click (function () {$ ("form. Required:input"). Trigger ('Blur');varNumerror = $ ("form. OnError"). length;var$id = $ ("form. OnError"). Prevall (". Required"). attr ("ID");if(numerror) {if(Numerror >1){$("#username"). focus ();}Else if($id = ="Email"){$("#email"). focus ();}return false;} Alert ("registration is successful, the password has been sent to your mailbox, please find");});
Learning the code needs to run a few more times!
JQ Combat-form validation