【发布时间】:2019-01-07 12:20:35
【问题描述】:
https://jsfiddle.net/8x7p682z/
function init() {
function setBackgroundForTimeOfDay() {
const body = document.querySelector('body');
const hours = new Date().getHours();
if (9 <= hours && hours <= 12)
body.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 231, 255),rgb(39, 38, 38))';
if (hours > 12 && hours <= 15)
body.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 255, 207),rgb(39, 38, 38))';
else
body.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 255, 207),rgb(39, 38, 38))';
}
}
function init1() {
function setBackgroundForTimeOfDay() {
const body = document.querySelector('body');
const hours = new Date().getHours();
if (9 <= hours && hours <= 12)
ul.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 231, 255),rgb(39, 38, 38))';
if (hours > 12 && hours <= 15)
ul.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 255, 207),rgb(39, 38, 38))';
else
ul.style['background-color'] = 'linear-gradient(to right, rgb(39, 38, 38), rgb(96, 255, 207),rgb(39, 38, 38))';
}
setBackgroundForTimeOfDay();
setInterval(setBackgroundForTimeOfDay, 60000);
}
这些是我的代码。 我编写了 java 脚本以根据用户的时间更改背景颜色和导航栏选择颜色。 但它不起作用。 你能帮我解决这个问题吗? 我是个新手。
【问题讨论】:
-
9 <= hour && hours <= 12s 和hours。 -
哦!我现在就更正一下。
-
为什么我看到这么多人不使用他们小提琴上漂亮而有用的 [Tidy] 按钮? (只是大声说出来,不要误会。:))
-
没有解决问题。问题依然存在。
-
我是一个完全的新手。给您带来的不便,我深表歉意。
标签: javascript html css bootstrap-4