【发布时间】:2011-06-11 05:33:34
【问题描述】:
我尝试在 Google 上进行研究,并在此处浏览了一些问题。我尝试了一些解决方案,但无法让它们发挥作用。
<td>
<img id="captcha" src="captcha.php" name="captcha" />
<img src="refresh.jpg" width="25" alt="" id="refresh_captcha" name="refresh_captcha" />
<input type="text" name="txtCaptcha" id="txtCaptcha" size="10" />
</td>
下面的代码不起作用:
$('.refresh_captcha').click(function(){
$('img').attr('src', 'captcha.php?cache=' + new Date().getTime());
});
我也试过这个:
$("#refresh_captcha").click(function() {
$("#captcha").attr("src","captcha.php?r=" + Math.random());
});
还有这个:
jQuery(function($) {
jQuery('#captcha').after("<a href=\"#\" id=\"refresh_captcha\">Refresh<\/a>");
jQuery('body').delegate('#refresh_captcha','click',function(){
jQuery.ajax({
'success':function(html){
jQuery("#captcha").attr("src",html)
},
'url':'/captcha.php?refresh=1',
'cache':false
});
return false;
});
});
有人可以帮助我吗?
【问题讨论】:
-
有什么问题?什么是“不工作”?
-
不工作意味着验证码不会刷新
-
$('.refresh_captcha')将不起作用,因为没有类名为refresh_captcha的元素,但第二个应该足够了。您是否看到每次单击时r的值都会随机化? -
另外,如果您直接在地址栏中访问
captcha.php并不断点击刷新,它会改变吗?如果不是验证码本身有问题 -
如果我自动刷新页面图像会改变
标签: php jquery refresh captcha