Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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 基于dytime更改div背景_Javascript_Html_Css_Background Image_Dst - Fatal编程技术网

Javascript 基于dytime更改div背景

Javascript 基于dytime更改div背景,javascript,html,css,background-image,dst,Javascript,Html,Css,Background Image,Dst,在特定的白天,我很难改变我的jumbotron背景,但没有显示任何内容,jumbotron也没有任何图片作为背景 我的Js: var currentTime = new Date().getHours(); if (7 <= currentTime && currentTime < 20) { if (document.getElementById("jumbotron")) { document.getElementById("jumbotr

在特定的白天,我很难改变我的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";
    }
}
var currentTime=new Date().getHours();

如果(7您需要使用正确的语法:

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

完整样本如下:


看看这个样本,谢谢你,阿伯