<img src="test.php" />
test.php 生成一个随机数图片。
我尝试过:
$('#verifyimage').click(function() {
$(this).attr('src',$(this).attr('src'));
});
但它不起作用。
<img src="test.php" />
test.php 生成一个随机数图片。
我尝试过:
$('#verifyimage').click(function() {
$(this).attr('src',$(this).attr('src'));
});
但它不起作用。
您可以通过在结尾添加一个随机字符串来强制刷新页面,从而改变URL:
$('#verifyimage').click(function() {
$(this).attr('src', $(this).attr('src')+'?'+Math.random());
});
添加时间戳或随机数:
var timestamp = new Date().getTime();
$(this).attr('src',$(this).attr('src') + '?' +timestamp );
借鉴KPrimes的优秀答案并结合Tracker的建议,我得出了以下结论:
jQuery(function($) {
// we have both a image and a refresh image, used for captcha
$('#refresh,#captcha_img').click(function() {
src = $('#captcha_img').attr('src');
// check for existing ? and remove if found
queryPos = src.indexOf('?');
if(queryPos != -1) {
src = src.substring(0, queryPos);
}
$('#captcha_img').attr('src', src + '?' + Math.random());
return false;
});
});
Content-Type:
的头部为 image/jpeg
。
Cache-control
,Expires
等只有在接收到HTTP请求后才起作用 - 上述内容仅是为了强制客户端发出该请求。在缺少Image.reload
(据我所知)的情况下,这是使新请求的最简单方法。 - K Prime