Merge pull request #25 from cw1997/master

增加支持验证码图片点击自动更换
This commit is contained in:
ThinkPHP
2018-06-07 11:24:56 +08:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -5,9 +5,9 @@ thinkphp5 验证码类库
> composer require topthink/think-captcha
##使用
## 使用
###模板里输出验证码
### 模板里输出验证码
~~~
<div>{:captcha_img()}</div>
@@ -18,6 +18,11 @@ thinkphp5 验证码类库
~~~
> 上面两种的最终效果是一样的
或者带有点击图片自动更换验证码的功能
~~~
<div>{:captcha_img_with_replacement()}</div>
~~~
### 控制器里验证
使用TP5的内置验证功能即可
~~~

View File

@@ -50,6 +50,19 @@ function captcha_img($id = '')
}
/**
* @param string $id
* @param string $element 验证码HTML元素ID
* @return string
*/
function captcha_img_with_replacement($id = '', $element = 'think-captcha')
{
return '<img src="' . captcha_src($id) . '" alt="' . $element .
'" id="think-captcha" onclick="document.getElementById("' . $element . '").src="' .
captcha_src($id) . '"+Math.random()' . '/>';
}
/**
* @param $value
* @param string $id