Home  >  Article  >  Web Front-end  >  jQuery Ajax displays right and wrong numbers to verify whether the input verification code is correct

jQuery Ajax displays right and wrong numbers to verify whether the input verification code is correct

韦小宝
韦小宝Original
2018-01-01 19:44:302544browse

This article mainly introduces jQuery Ajax to display correct and incorrect numbers to verify whether the input verification code is correct. Friends who are interested in ajax can refer to this article!

Without further ado, I will post the code directly for you. The specific code is as follows:


<script src="js/j.js"></script>
<script>
$(document).ready(function(e) {
 $(&#39;#yes&#39;).hide();
 $(&#39;#no&#39;).hide();
  $(&#39;input[name=gcode]&#39;).keyup(function(){
   if($(this).val().length==4){
  $.post(&#39;gbook.php&#39;,{cc:$(&#39;input[name=gcode]&#39;).val()},function(msg){
   
   if(msg==&#39;yes&#39;){
    $(&#39;#no&#39;).hide();
    $(&#39;#yes&#39;).show();
   }else{
    $(&#39;#yes&#39;).hide();
    $("#no").show();
   }
  });
  }
 });
});
</script>


## First introduce the html code of 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;
}


verification code


<tr>
  <td height="40" align="right">验证码:</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>
  <img style="float:right; margin-top:-25px; margin-right:300px;" align="middle" src="inc/cc.php" onClick="this.src=&#39;inc/cc.php?&#39;+new Date" title="点击换一张图片" width="100px"></td>
 </tr>


gbook.php


<?php
session_start();
if(isset($_POST[&#39;cc&#39;])){
 $cc = strtolower($_POST[&#39;cc&#39;]);
 $ss = strtolower($_SESSION[&#39;code&#39;]);
 if($cc==$ss){
   echo "yes";
 }else{
   echo "no"; 
 }
}


##Note that pictures must be imported

The above is the jQuery Ajax introduced by the editor to display correct and incorrect numbers to verify whether the input verification code is correct. I hope it will be helpful to everyone! !

Related recommendations:

Example detailed explanation to quickly obtain Ajax communication objects

Native ajax waterfall flow demo example sharing

Examples to explain H5 mobile development Ajax upload multiple Base64 format pictures to the server

The above is the detailed content of jQuery Ajax displays right and wrong numbers to verify whether the input verification code is correct. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn