验证码单击刷新问题

    //生成验证码
<?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语法请讲解一下,谢谢。

阅读 5.1k
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>

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题