我在特定日期更改超大屏幕背景时遇到问题,但没有任何显示,而且超大屏幕没有任何图片作为背景。
我的 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";
}
}
最佳答案
您需要使用正确的语法:
document.getElementById("jumbotron").style.backgroundImage = "url('1.jpg')";
http://www.w3schools.com/jsref/prop_style_backgroundimage.asp
完整示例在这里:
关于javascript - 在 dytime 基础上更改 div 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37374676/