重新加载图像而不刷新页面

重新加载图像而不刷新页面

问题描述:

JavaScript:

Javascript:

function atualiza() {
  document.getElementById('badge').innerHTML = location.reload();
}

我知道"location.reload()"将刷新页面...

I know the "location.reload()" will refresh the page...

HTML:

<img id="badge" src="<?php echo $cms_url; ?>/imaging/badge.php?badge=$mygroup['badge']; ?>" />

我需要在不刷新页面的情况下刷新 src =" < img/> .

I need to freshed the src="" or <img /> without refreshing the page.

将您的 img 标记更改为此:

<img id="badge" src="$cms_url/imaging/badge.php?badge=$mygroup['badge']; ?>">/imaging/badge.php?badge=<?php echo $mygroup['badge']; ?>" />

然后,您可以使用以下代码通过单击按钮,锚点或其他任何方式来更改图像源:

Then you can use below code to change your image source on click of a button, anchor or whatever:

document.getElementById("badge").src="new image src here";

您也可以使用jQuery:

You can use jQuery as well:

$("#badge").attr("src", "new image src here");