Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用javascript加载图像不会';更新图片更新_Jquery_Html_Css_Wamp - Fatal编程技术网

Jquery 使用javascript加载图像不会';更新图片更新

Jquery 使用javascript加载图像不会';更新图片更新,jquery,html,css,wamp,Jquery,Html,Css,Wamp,我在使用wamp时遇到一些问题,当我编辑(在外部程序中)用javascript加载的图像时,它不会在Web服务器上更新 我使用这段代码加载图像作为h2标记的背景 $('div.drawer h2').each(function(index) { $(this).css("background-image", "url(./images/" + $(this).text() + ".png)") }); 这将从images文件夹中加载包含h2+.png文本的图像 但是,它不会在缓存中重新

我在使用wamp时遇到一些问题,当我编辑(在外部程序中)用javascript加载的图像时,它不会在Web服务器上更新

我使用这段代码加载图像作为h2标记的背景

$('div.drawer h2').each(function(index)
{
    $(this).css("background-image", "url(./images/" + $(this).text() + ".png)")
});
这将从images文件夹中加载包含h2+.png文本的图像

但是,它不会在缓存中重新加载图像,因此如果我编辑源图像,它不会在网页上更改

如果我在CSS中加载图像(使用background image变量),它会很好地加载和更新


如何修复此行为?图像可能缓存在您的web浏览器中,请尝试按ctrl+F5重新加载图像

或者您可以尝试ctrl+delete并删除浏览器的整个缓存,看看这是否是您的问题

如果在javascript中动态加载图像,可以在图像名称后添加?randomnumber

这样,URL对于每个请求都是唯一的,因此不会命中浏览器的缓存