search

Home  >  Q&A  >  body text

javascript - 验证码单击刷新问题

    //生成验证码
<?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中文网2902 days ago442

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-04-10 14:58:26

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

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

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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-10 14:58:26

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

    </html>

    reply
    0
  • 怪我咯

    怪我咯2017-04-10 14:58:26

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

    为了刷新图片不缓存

    reply
    0
  • 黄舟

    黄舟2017-04-10 14:58:26

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

    reply
    0
  • Cancelreply