我有以下 switch 语句:
switch (result.innerHTML) {
case "":
case " ":
result.innerHTML = "Stage1";
result.style.backgroundColor = "green";
break;
case "Stage1":
result.innerHTML = "Stage2";
result.style.backgroundColor = "red";
break;
case "Stage2":
result.innerHTML = "Stage3";
result.style.backgroundColor = "yellow";
break;
case "Stage3":
result.innerHTML = "Stage4";
result.style.backgroundColor = "pink";
break;
case "Stage4": //start over
result.innerHTML = "";
result.style.backgroundColor = "";
break;
default:
}
在 JavaScript 中还有另一种简洁的方法吗?也许使用数组或 JavaScript 对象?