在javascript中设置线性颗粒

在javascript中设置线性颗粒,javascript,html,css,Javascript,Html,Css,这是我当前的代码,我正在尝试将我的网站背景设置为彩虹渐变,但是这段代码不起作用,但是我知道它会在页面上发出警报时被调用?我该如何着手解决这个问题 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 (

这是我当前的代码,我正在尝试将我的网站背景设置为彩虹渐变,但是这段代码不起作用,但是我知道它会在页面上发出警报时被调用?我该如何着手解决这个问题

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

请参见此处的示例:

var-date=新日期();
var hours=date.getHours();
var day=date.getDay();
var seconds=date.getSeconds();
var minutes=date.getMinutes();
var month=date.getMonth();
如果(月份==4){
document.getElementById(“container”).style.background=`线性渐变(红、黄、绿)`;
}
#容器{
宽度:500px;
高度:500px;
}

使用
style.backgroundImage
这是否回答了您的问题?来自MDN:创建由两种或两种以上颜色沿直线的渐进过渡组成的图像。其结果是数据类型的对象,这是一种特殊的