JQuery Ajax displays the check mark and error number to verify that the entered verification code is correct. jqueryajax
If you don't talk much about it, paste the Code directly. The specific code is as follows:
<script src="js/j.js"></script><script>$(document).ready(function(e) { $('#yes').hide(); $('#no').hide(); $('input[name=gcode]').keyup(function(){ if($(this).val().length==4){ $.post('gbook.php',{cc:$('input[name=gcode]').val()},function(msg){ if(msg=='yes'){ $('#no').hide(); $('#yes').show(); }else{ $('#yes').hide(); $("#no").show(); } }); } });});</script>
First introduce jquery
.sl-error-verifycode { background-image: url("images/icons.png"); background-position: -26px 0; background-repeat: no-repeat; display: block; font-size: 18px; height: 23px; line-height: 20px; margin-left: 180px; margin-top: -25px; position: relative; text-align: center; width: 20px; z-index: 2;}.sl-correct-verifycode { background-image: url("images/icons.png"); background-position: -50px 0; background-repeat: no-repeat; display: block; font-size: 18px; height: 23px; line-height: 20px; margin-left: 180px; margin-top: -25px; position: relative; text-align: center; width: 20px; z-index: 2;}
Html code of the Verification Code
<Tr> <td height = "40" align = "right"> Verification Code: </td> <td height = "40"> <span class = "addred"> * </span> </td> <td height = "40"> <input type = "text" name = "gcode" id = "textfield7" class = "txtlist"> <span id = "yes" class = "sl-correct-verifycode"> </span> <span id = "no" class = "sl-error-verifycode"> </span> </td> </tr>
Gbook. php
<?phpsession_start();if(isset($_POST['cc'])){ $cc = strtolower($_POST['cc']); $ss = strtolower($_SESSION['code']); if($cc==$ss){ echo "yes"; }else{ echo "no"; }}
Note that images must be imported
The preceding section describes how to use jQuery Ajax to display the check mark and error number to verify whether the entered verification code is correct. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!