问题
I'm using
$("#my_img").attr("src", "/another_img.png");
inside the "beforeSend" callback of an Ajax request using jQuery, the problem is that the the img isn't being always refreshed to the user, sometimes I saw the new image and sometimes not, is there anyway to force the refresh of the img ? I was thinking that by changing the "src" attribute of the img element was enough to make the engine refresh the image. Thanks !
回答1:
Sounds like it might be a caching issue, try:
$("#my_img").attr("src", "/another_img.png?v=" + new Date().getTime());
来源:https://stackoverflow.com/questions/8423626/changing-src-of-an-img-html-element-doesnt-refresh-it