宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

这篇文章主要介绍了jQuery Ajax显示对号和错号用于验证输入验证码是否正确的相关ajax资料,对ajax感兴趣的朋友可以参考下本篇文章哦!

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<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>

登录后复制

首先引入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 代码

<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='inc/cc.php?'+new Date" title="点击换一张图片" width="100px"></td>
 </tr>

登录后复制

gbook.php

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

登录后复制

注意图片一定要引入

jQuery Ajax显示对号和错号用于验证输入验证码是否正确-风君雪科技博客

以上所述是小编给大家介绍的jQuery Ajax显示对号和错号用于验证输入验证码是否正确,希望对大家有所帮助!!

相关推荐:

实例详解快速获取Ajax通信对象

原生ajax瀑布流demo实例分享

实例讲解H5移动开发Ajax上传多张Base64格式图片到服务器

以上就是jQuery Ajax显示对号和错号用于验证输入验证码是否正确的详细内容,更多请关注风君子博客其它相关文章!