素材牛VIP会员
验证码单击刷新问题
 那***美  分类:ThinkPHP  人气:947  回帖:4  发布于6年前 收藏
    //生成验证码
<?php
    public function showVerify(){

        $data = array(
            'fontSize'  =>  30,
            'length'    =>  3,  
            'useNoise'  =>  true,
            'useCurve'  =>  false,
        );
        $Verify = new \Think\Verify($data);
        $Verify->entry();

    }


在另一处调用showVerify()

 <img src="__CONTROLLER__/showVerify" width="60" onclick="if(this.src!=this.src+'?'+Math.random) this.src=this.src+'?'+Math.random()"/> 

请问:

if(this.src!=this.src+'?'+Math.random) this.src=this.src+'?'+Math.random()

这句javascript语法请讲解一下,谢谢。

 标签:thinkphpjavascript

讨论这个帖子(4)垃圾回帖将一律封号处理……

Lv6 码匠
飞***猪 交互设计师 6年前#1

http://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url

为了刷新图片不缓存

Lv2 入门
th***as 职业无 6年前#2

//问题补充
//在另一处调用showVerify()
<html>

</html>

Lv6 码匠
lu***ng 软件测试工程师 6年前#3

@Chobits 已经说了它的用途,这里自己再补充一点。

    if(this.src!=this.src+'?'+Math.random)

这个if判断应该总是true的,所以this.src=this.src+'?'+Math.random()总是会执行。
应该直接去掉if(this.src!=this.src+'?'+Math.random)这个条件判断,毕竟这里没实际意义。

Lv4 码徒
逆***团 Linux系统工程师 6年前#4

如果验证码变了,那么显示新的验证码

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取