首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过JS设置时在IE中不工作的背景图像

通过JS设置时在IE中不工作的背景图像
EN

Stack Overflow用户
提问于 2017-11-03 11:42:21
回答 1查看 233关注 0票数 0

我正在尝试设置来自javascript结束的背景图像。我的代码在Chrome中运行良好,但在IE11中测试时,图像没有显示。

代码语言:javascript
复制
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没有任何作用。所以请不要把这个标记为副本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-03 11:58:45

我认为问题在于你的语法错误。基本上,.background具有以下语法:

代码语言:javascript
复制
object.style.background = "color image repeat attachment position size origin clip|initial|inherit"

图像在哪里

代码语言:javascript
复制
object.style.backgroundImage = "url('URL')|none|initial|inherit"

所以,我认为proplem在引号中。图像路径应该作为url的字符串值。示例:

代码语言:javascript
复制
document.getElementById("myDIV").style.background = "url('smiley.gif') blue repeat-x center";

所以,试试这个:

代码语言:javascript
复制
document.getElementById('loginLogo').style.background = "url('./images/custom/'" + logo[name] + "') no-repeat center bottom";
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47094965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档