我正在尝试设置来自javascript结束的背景图像。我的代码在Chrome中运行良好,但在IE11中测试时,图像没有显示。
function setApplicationLogo() {
var name = getApplicationName();
if (name) {
document.getElementById('loginLogo').style.background = 'url(./images/custom/' + logo[name] + ')no-repeat center bottom';
} else {
document.getElementById('loginLogo').style.background = 'url(./images/logo77.gif)no-repeat center bottom';
}
}我知道修复是相当直接的,但我抓我的头在过去的2-3个小时。我尝试过将background更改为backgroundImage,并在no-repeat之前删除添加/删除空间,但对IE没有任何作用。所以请不要把这个标记为副本。
发布于 2017-11-03 11:58:45
我认为问题在于你的语法错误。基本上,.background具有以下语法:
object.style.background = "color image repeat attachment position size origin clip|initial|inherit"图像在哪里
object.style.backgroundImage = "url('URL')|none|initial|inherit"所以,我认为proplem在引号中。图像路径应该作为url的字符串值。示例:
document.getElementById("myDIV").style.background = "url('smiley.gif') blue repeat-x center";所以,试试这个:
document.getElementById('loginLogo').style.background = "url('./images/custom/'" + logo[name] + "') no-repeat center bottom";https://stackoverflow.com/questions/47094965
复制相似问题