Home > Backend Development > PHP Tutorial > TP大神帮我看看,验证码不能刷新,。JS有问题吗?

TP大神帮我看看,验证码不能刷新,。JS有问题吗?

WBOY
Release: 2016-06-23 13:33:19
Original
868 people have browsed it

<script> //验证码生成   var captcha_img = $('#captcha-container').find('img')   var verifyimg = captcha_img.attr("src");  captcha_img.attr('title', '点击刷新');  captcha_img.click(function(){      if( verifyimg.indexOf('?')>0){          $(this).attr("src", verifyimg+'&random='+Math.random());      }else{          $(this).attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());      }   });   </script>
Copy after login


 <p class="clearfix" id="captcha-container">            <label class="one" for="agent">验证码:</label>            <input style="width:15%;" id="agent" name="verify" type="text" class="captcha-text" value placeholder="请输入验证码" />            <img width="25%" class="left15"    style="max-width:90%" alt="验证码" src="{:U('Home/Index/verify_c',array())}" title="点击刷新">        </p>
Copy after login


回复讨论(解决方案)

先确保 Home/Index/verify_c 这个地址能够正常的刷一次换一个验证码

其次你的地址是否会自动把?random=2转化为/random/2这样

TP大神帮我看看,验证码不能刷新,。JS有问题吗?
没有看到 img 点击事件 onclick 的代码,难道 TP 会替你生成吗?
请在浏览页 网页源代码 中确认一下

先检查下加载的URL是否能正常生成验证码,然后你再检测下js代码是否能正常的让img加载click事件,最后在做点击刷新。

首先 用firebug 看下  有没js报错, 然后在click事件里 逐步alert('test')  追踪下

已经解决,谢谢大家。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template