页面显示验证码:
<div class="input-group has-feedback "> <input id="yzm" type="text" name="yzm" class="form-control" placeholder="验证码" style="100px;" /> <!--<span class="glyphicon glyphicon-qrcode form-control-feedback" style="right:120px;"></span>--> <span><img id="src" class="verify" src="{:U(verify)}" alt="验证码" /></span> <span id="btn">换一张</span> </div> <script> $("#btn").click(function(){ var a = Math.ceil(Math.random()*100); $(".verify").attr("src","__CONTROLLER__/verify/a/"+a+""); }) </script>
当然:src="{:U(verify)}" 也可以换成src="__CONTROLLER__/verify";
验证码也可以换成是点击图片换一张,代码如下:<span><img class="verify" src="{:U(verify)}" alt="验证码" Onclick="this.src=this.src+'?'+Math.random()" "/></span>
还可以用js <script>
$("#src").click(function(){
var a = Math.ceil(Math.random()*100);红色的代码代表是随机数,蓝色的代表向上取整
$(tihs).attr("src","__CONTROLLER__/verify/a/"+a+"");
})
</script>
控制器验证码的操作方法:实例化Verify对象和$verify->entry(); 就可以显示出验证码
public function verify() { // 实例化Verify对象 $verify = new ThinkVerify(); // 配置验证码参数 $verify->fontSize = 14; // 验证码字体大小 $verify->length = 4; // 验证码位数 $verify->imageH = 34; // 验证码高度 $verify->useImgBg = false; // 开启验证码背景 $verify->useNoise = false; // 关闭验证码干扰杂点 $verify->entry(); }