这是我当前的代码,我正试图将我的网站背景设置为彩虹渐变,但此代码不起作用,但我知道它是在页面上警报响起时调用的?我该怎么解决这个问题?
var date = new Date();
var hours = date.getHours();
var day = date.getDay();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var month = date.getMonth();
if (month == 4) {
document.getElementById("container").style.backgroundColor = `linear-gradient(red, yellow, green)`;
alert("test");
}
使用el.style.background
而不是backgroundColor
。
请参阅此处的示例:MDN linear-gradient((
var date = new Date();
var hours = date.getHours();
var day = date.getDay();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var month = date.getMonth();
if (month == 4) {
document.getElementById("container").style.background = `linear-gradient(red, yellow, green)`;
}
#container {
width: 500px;
height: 500px;
}
<div id="container"></div>