0
我試着在Google上進行研究,並在這裏瀏覽了一些問題。我嘗試了一些解決方案,但我無法讓他們工作。使用jQuery問題進行驗證碼刷新
<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;
});
});
任何人都可以幫助我?
有什麼問題?什麼是「不工作」? – corroded 2011-06-11 06:09:06
工作不意味着驗證碼不會刷新 – user236501 2011-06-11 06:10:33
'$(「 refresh_captcha」)'將無法工作,因爲沒有與類名'refresh_captcha'但第二個應該夠沒有元素。你看到'r'的值每次點擊都隨機化了嗎? – tradyblix 2011-06-11 06:16:00