thinkphp5点击验证码实现刷新

发布时间:2023-11-20作者:豆子点击:85

问题描述:
       当我们使用{:captcha_img()}调用验证码的时候,并没有点击验证码就能实现刷新的功能。
解决办法:
   在根目录下找到
      vendor\topthink\think-captcha\src\helper.php 

第一种办法:47行左右添加onclick。


  1. function captcha_img($id = "")
  2. {
  3.     return '<img src="' . captcha_src($id) . '"  alt="点击更换"  onclick="this.src=\''.captcha_src().'?id=\'+Math.random();" />';
  4. }

第二种办法:在模板中直接添加下面的代码
<img onclick="this.src='{:captcha_src()}?'+Math.random()" src="{:captcha_src()}" alt="captcha" />
提交后刷新验证码
var src = '{:captcha_src()}?' + Math.random();
            $(".VcodeImg").attr("src", src);
标签:thinkphp5验证码,tp5验证码刷新