验证码登录需要检验+jquery+js

2010-10-09 17:08:01 by 【6yang】, 672 visits, 收藏 | 返回

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>验证码登录需要检验+jquery+js</title>
</head>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
jQuery(function($){
  function checkVerifyCode(A){
   if(0==A.length){
    return 1
   }else{
    if(4==A.length){
     return 0
    }
   }
   return 2
  }
  
  var checkvcajax = function(vName,issubmit){
   var ret = checkVerifyCode($("#verifycode").val());
    if( ret==0){
     if(issubmit){
      var verifycode = $("#verifycode").val();
      var url="ajax.php";
      var oData={str:verifycode};
      $.post(url, oData, function(json){
       if(json.status == "successful"){
        $("#verifytip").hide();
        $("#ProcessLoginForm").submit(); 
       }else{ 
        $("#verifycode").focus();
        $("#verifytip")[0].innerHTML="您输入的验证码有误";
       }
      },"json");
     }else{
      $("#tips").hide();
     }
    }
    else if(ret==1){//空
     $("#verifytip")[0].style.display=""; 
     $("#verifytip")[0].innerHTML="请输入验证码";
    }else{
     $("#verifytip")[0].style.display=""; 
     $("#verifytip")[0].innerHTML="您输入的验证码有误";
    }    
  }; 
 //// 

 $("#submit").click(function(){
  if ($("#username").val() == "")
  { 
   $("#usernametip").text("请输入用户名");
   return false;  
  }
  
  if ($("#password").val() == "")
  { 
   $("#passwordtip").text("请输入密码");
   return false;  
  }
  
  checkvcajax($("#verifycode").val(),true);//必须在最后调用    
  //return false;
 });
 
 $("#verifycode").blur(function(){
  checkvcajax($(this).val(),false);
 });
});
</script>
<body>
</body>
 <form  action="xxx.php" method="post"  name="login" id="ProcessLoginForm" >                         
 <input type="text" name="username" value=""  id="username"/><span id="usernametip" ></span><br/><br/>
 <input type="text" name="password" value=""  id="password"/><span id="passwordtip" ></span><br/><br/>
 <input type="text" name="" id="verifycode" />yang <span id="verifytip"></span><br/><br/>
 <a href="#"   id="submit"/>登录</a>
</form>
</html>

分享到:
share

    图片原图

    loading

    loading