javascript - 验证码单击刷新问题
PHP中文网
PHP中文网 2017-04-10 14:56:26
0
4
445
    //生成验证码
<?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语法请讲解一下,谢谢。

PHP中文网
PHP中文网

认证0级讲师

모든 응답(4)
刘奇

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

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

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

左手右手慢动作

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

</html>

刘奇

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

为了刷新图片不缓存

黄舟

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

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿