输出验证方法:
public function verify(){ $config = array( ‘length‘ => 2, ‘reset‘ => false, ‘useCurve‘ => false, ‘useNoise‘ => false, ); $obj = new \Think\Verify($config); $obj->entry(); }
调用:
<img src="{:U(‘verify‘)}"/ id=‘code‘> <a href="javascript:void(change_code(this));">看不清</a>
输入路径:
<script type=‘text/javascript‘> var CONTROL = ‘__URL__‘; </script>
点击切换验证码:
function change_code(obj){ $("#code").attr("src", CONTROL+"/verify/"+Math.random()); return false; }
异步验证验证码方法:
/* 异步验证验证码 */ public function checkVerify(){ $code = I(‘post.code‘); $config = array( ‘reset‘ => false,//不重置 ); $obj = new \Think\Verify($config); if($obj->check($code)){ echo "1"; }else{ echo "0"; }; }
异步验证验证码JS:
//验证验证码 $("input[name=‘code‘]").blur(function(){ var code = $("input[name=‘code‘]"); if(code.val().trim()==‘‘){ code.parent().find("span").remove().end().append("<span class=‘error‘>验证码不能为空</span>"); return ; } $.post(CONTROL+"/checkVerify",{code:code.val().trim()},function(stat){ if(stat==1){ validate.code=0; code.parent().find("span").remove(); }else{ code.parent().find("span").remove().end().append("<span class=‘error‘>验证码错误</span>"); } }) })
时间: 2024-10-24 11:16:44