javascript - 验证码单击刷新问题
PHP中文网
PHP中文网 2017-04-10 14:56:26
[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中文网

认证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)这个条件判断,毕竟这里没实际意义。

ringa_lee

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

</html>

怪我咯

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

为了刷新图片不缓存

黄舟

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号