我试图使这个脚本更简洁,因为我将来会添加更多的语句。
x = Math.floor((Math.random() * 9) + 1);
var one = document.getElementById("test");
if(x === 1) {
one.style.backgroundColor = "red";
}
if(x === 2) {
one.style.backgroundColor = "blue";
}
if(x === 3) {
one.style.backgroundColor = "yellow";
}