代码示例:(标识:eg_js_switch_4)
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript switch</h2>

<p id="demo"></p>

<script>
var text;
switch (new Date().getDay()) {
  case 4:
  case 5:
    text = "周末马上就到了";
    break;
  case 0:
  case 6:
    text = "今天是周末";
    break;
  default:
    text = "期待周末";
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>
运行结果: