1,在home模块indexController.class.php中,加入以下代码
<?php namespace Home\Controller; use Think\Controller; class BookController extends Controller { public function verify_c(){ $Verify = new \Think\Verify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = ‘0123456789‘; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); } public function img(){ $this->display(); } }
2. 在img 视图中,加入以下代码
<script type="text/javascript" src="__PUBLIC__/js/jquery2.0.3.min.js"></script> <p class="top15 captcha" id="captcha-container"> <input name="verify" width="50%" height="50" class="captcha-text" placeholder="验证码" type="text"> <img width="100" class="left15" height="50" alt="验证码" src="{:U(‘Home/Book/verify_c‘,array())}" title="点击刷新"> </p> <script type="text/javascript"> $(function(){ var captcha_img = $(‘#captcha-container‘).find(‘img‘); var verifyimg = captcha_img.attr("src"); captcha_img.attr(‘title‘, ‘点击刷新‘); captcha_img.click(function(){ if( verifyimg.indexOf(‘?‘)>0){ $(this).attr("src", verifyimg+‘&random=‘+Math.random()); }else{ $(this).attr("src", verifyimg.replace(/\?.*$/,‘‘)+‘?‘+Math.random()); } }); }) </script>
这样就可以了,就能显示出 验证码了。
参考学习 网址:http://blog.csdn.net/yafei450225664/article/details/40424025
时间: 2024-11-29 06:59:06