Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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
Javascript 动态加载的CSS背景图像未在Chrome中显示_Javascript_Jquery_Html_Css_Google Chrome - Fatal编程技术网

Javascript 动态加载的CSS背景图像未在Chrome中显示

Javascript 动态加载的CSS背景图像未在Chrome中显示,javascript,jquery,html,css,google-chrome,Javascript,Jquery,Html,Css,Google Chrome,我正在为组织制作github gist图库,您可以在上看到 缩略图通过javascript放置在页面上,背景图像设置为内联样式规则。在Firefox和Internet Explorer中显示背景图像,而在Chrome和Safari中则不显示 在firefox中,以下代码返回背景图像的正确url,而在chrome中返回“none”: $($(“.缩略图”)[0]).css(“背景图像”) 因此,我无法使用: 我尝试过在url中添加单引号,正如一些人在其他人出现类似问题时所建议的那样。如果我查看“网

我正在为组织制作github gist图库,您可以在上看到

缩略图通过javascript放置在页面上,背景图像设置为内联样式规则。在Firefox和Internet Explorer中显示背景图像,而在Chrome和Safari中则不显示

在firefox中,以下代码返回背景图像的正确url,而在chrome中返回
“none”

$($(“.缩略图”)[0]).css(“背景图像”)

因此,我无法使用:

我尝试过在url中添加单引号,正如一些人在其他人出现类似问题时所建议的那样。如果我查看“网络”选项卡,它甚至从不请求图像。如果我在ChromeDevTools中手动将背景图像属性设置为一个新规则,它会起作用,因此我知道这不是url格式的问题,也不是愚蠢的语法错误

chrome中有没有解决这个问题的方法

更改
$this.css(“背景图像”,oldBackgroundImage)
$this.css('background-image','url('+oldBackgroundImage+'))

此外(或者更确切地说),在我的浏览器中,由于url()声明中缺少右括号,因此背景图像样式的分析不正确。修复该问题,然后可以使用$().css()检索背景图像

细节:我明白了


应该是

 <a style="background-image: url(//../thumbnail.png)" class="gist thumbnail" href="..">


我可能错了,但我认为
$此
$(此)
的内存副本,不会影响DOM。尝试在代码中用
$(this)
替换
$this
$this
仍然引用DOM节点,它只是避免了每次要求jQuery查找它。我试着改变它,但它并没有解决问题。哦,值得一试,我想这并不能解决问题。在firefox中,
oldBackgroundImage==“url(”https://gist.githubusercontent.com/elsherbini/13383ffc376b54ad34ea/raw/55fbdfcf4d76dde2e6e3d1b638aacd47cd3aed33/thumbnail.png“”“
(它已经有了
url()
部分)。在Chrome中,
oldBackgroundImage==“无”
。不是这样吗?是的,它在firefox中工作。为了确保代码正常工作,我在firefox中运行了它(没有对用户代理进行测试),并且它正确地重置了背景图像。如果你喜欢,你可以自己尝试,链接在问题的顶部。这就是问题所在。看起来firefox和IE都解析了错误的css,但是Chrome因为我的下划线模板的问题而放弃了这个规则。谢谢
 <a style="background-image: url(https://../thumbnail.png" class="gist thumbnail" href="..">
 <a style="background-image: url(//../thumbnail.png)" class="gist thumbnail" href="..">