Event application in the text box: Take the input email as an example, as shown in the figure: The code is as follows: Copy the code The code is as follows: <br>body{ font-size:13px;} <br>/*Element initialization style*/ <br>.divInit{ width:390px; height:55px; line-height:55px; padding-left:20px;} <br>.txtInit{ border:solid 1px #666; padding:3px; background-image:url( 'Images/bg_email_input.gif');} <br>.spnInit{ width:179px; height:40px; line-height:40px; float:right; margin-top:8px; padding-left:10px; background-repeat: no-repeat;} <br>/*Element loses focus style*/ <br>.divBlur{ background-color:#FEEEC2;} <br>.txtBlur{ border:solid 1px #666; padding:3px; background-image :url('Images/bg_email_input2.gif');} <br>.spnBlur{ background-image:url('Images/bg_email_wrong.gif');} <br>.divFocu{ background-color:#EDFFD5;} / *div gets focus style*/ <br>.spnSucc{ background-image:url('Images/pic_Email_ok.gif'); margin-top:20px;} /*span style when verification is successful*/ <br></ style> <br><script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> <br><script src="Scripts/jquery- 1.4.1.js" type="text/javascript"></script> <br><script type="text/javascript"> <br>$(function () { <br>$(" #txtEmail").trigger("focus"); //The text box gets focus by default<br>$("#txtEmail").focus(function () { //The text box gets focus event<br>$(this ).removeClass("txtBlur").addClass("txtInit"); <br>$("#email").removeClass("divBlur").addClass("divFocu"); <br>$("#spnTip" ).removeClass("spnBlur").removeClass("spnSucc").html("Please enter your usual email address! "); <br>}); <br>$("#txtEmail").blur(function () { //Text box loses focus event<br>var vTxt = $("#txtEmail").val() ; <br>if (vTxt.length == 0) { //Whether the email address is entered in the text box<br>$(this).removeClass("txtInit").addClass("txtBlur"); <br>$( "# email").removeClass("divFocu").addClass("divBlur"); <br>$("#spnTip").addClass("spnBlur").html("Email address cannot be empty!"); <br>} <br>else { //Check whether the email format is correct<br>if (!chkEmail(vTxt)) { //If it is incorrect<br>$(this).removeClass("txtInit").addClass( "txtBlur"); <br>$("#email").removeClass("divFocu").addClass("divBlur"); <br>$("#spnTip").addClass("spnBlur").html( "The email format is incorrect!"); <br>} <br>else { //If correct<br>$(this).removeClass("txtBlur").addClass("txtInit"); <br>$(" #email").removeClass("divFocu"); <br>$("#spnTip").removeClass("spnBlur").addClass("spnSucc").html(""); <br>} <br> } <br>}); <br>/*Verify whether the email format is correct. Parameter strEmail, the email that needs to be verified*/ <br>function chkEmail(strEmail) { <br>var vChk = /^w ([- .]w )*@w ([-.]w )*.w ([-.]w )*$/; <br>if (!vChk.test(strEmail)) { <br>return false; <br>} <br>else { <br>return true; <br>} <br>} <br>}); <br></script> <br></head> <br><body> <br> <form id="form1" action="#"> <br><div id="email" class="divInit">Email: <br><span id="spnTip" class="spnInit "></span> <br><input type="text" id="txtEmail" class="txtInit" /> <br></div> <br></form> <br></body> <br></html> <br> </div>