<img src="test.php" />
Run Code Online (Sandbox Code Playgroud)
其中test.php生成一个随机数的图像.
我试过了 :
$('#verifyimage').click(function() {
$(this).attr('src',$(this).attr('src'));
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
K P*_*ime 58
您可以通过在末尾附加随机字符串来强制刷新,从而更改URL:
$('#verifyimage').click(function() {
$(this).attr('src', $(this).attr('src')+'?'+Math.random());
});
Run Code Online (Sandbox Code Playgroud)
添加时间戳或随机数:
var timestamp = new Date().getTime();
$(this).attr('src',$(this).attr('src') + '?' +timestamp );
Run Code Online (Sandbox Code Playgroud)
考虑到KPrimes很好的答案并添加跟踪器建议,这就是我想出的:
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;
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56766 次 |
| 最近记录: |