【问题标题】:Change div background on dytime basis在 dytime 的基础上更改 div 背景
【发布时间】:2016-09-19 08:54:15
【问题描述】:

我无法在特定时间更改我的 jumbotron 背景,但没有显示任何内容,并且 jumbotron 没有任何图片作为背景。

我的 Js:

var currentTime = new Date().getHours();
if (7 <= currentTime && currentTime < 20) {
    if (document.getElementById("jumbotron")) {
        document.getElementById("jumbotron").background = "1.jpg";
    }
}else {
    if (document.getElementById("jumbotron")) {
        document.getElementById("jumbotron").background = "2.jpg";
    }
}

【问题讨论】:

标签: javascript html css background-image dst


【解决方案1】:

你需要使用正确的语法:

document.getElementById("jumbotron").style.backgroundImage = "url('1.jpg')";

http://www.w3schools.com/jsref/prop_style_backgroundimage.asp

完整示例在这里:

https://jsfiddle.net/gevorgha/15baqpjt/

【讨论】:

  • 已解决谢谢 aber
猜你喜欢
  • 2013-11-27
  • 2022-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多