如何刷新< img/>的src用jQuery? [英] How to refresh the src of <img /> with jQuery?

查看:89
本文介绍了如何刷新< img/>的src用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<img src="test.php" />

其中test.php生成具有随机数的图像.

where test.php generates an image with a random number.

已迭代:

$('#verifyimage').click(function() {
        $(this).attr('src',$(this).attr('src'));
    });

但这是行不通的.

推荐答案

您可以通过在末尾添加随机字符串来强制刷新,从而更改URL:

You can force a refresh by appending a random string at the end, thus changing the URL:

$('#verifyimage').click(function() {
    $(this).attr('src', $(this).attr('src')+'?'+Math.random());
});

这篇关于如何刷新&lt; img/&gt;的src用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆