所以我有一个主页,上面有一些代码可以根据时间更改背景。我的问题是:它只检查首次加载页面的时间,我需要它不断对其进行检查。这是我的代码,请帮忙。
var today2 = new Date();
var h2 = today2.getHours();
if (h2 > 18) {
document.body.style.backgroundImage = "url('cityatnight2.jpg')";
}
else if (h2 < 9) {
document.body.style.backgroundImage = "url('sunrise2.jpg')";
}
else {
document.body.style.backgroundImage = "url('homescreen3.jpg')";
}
答案 0 :(得分:1)
尝试此代码。
var changeBg = function(num){
if (num > 18) {
document.body.style.backgroundColor = "red";
}
else if (num < 9) {
document.body.style.backgroundColor = "blue";
}
else {
document.body.style.backgroundColor = "black";
}
}
setInterval(function(){
var today2 = new Date();
var h2 = today2.getSeconds(); //edit here. sec -> hour.
console.log(h2)
changeBg(h2);
},1000) //and edit here. 1000 means 1sec
答案 1 :(得分:1)
我建议使用tempplc = '/mnt/Volume_1/USB_DRIVE/'
mvs = []
tvs = []
tds = []
for item in dwnlds:
result = re.search(r"s\d\de", item, re.I)
tdsrlt = re.search(r"the.daily.show", item, re.I)
if result == None:
if tdsrlt != None:
tds.append(item)
else:
mvs.append(item)
else:
tvs.append(item)
os.chdir('/mnt/Data/jails_2/sabnzbd_1/var/db/sabnzbd/Downloads/complete')
for item in tds:
os.system('mv -v item tempplc') #<---- PROBLEM LINE
命令。它允许您指定代码以给定的间隔运行。例如,要每小时运行一次,您可以这样做:
setInterval
在此处详细了解该功能:https://www.w3schools.com/jsref/met_win_setinterval.asp