<h2>JavaScript switch</h2> <p id="demo"></p> <script> var x = "0"; switch (x) { case 0: text = "Off"; break; case 1: text = "On"; break; default: text = "未找到值"; } document.getElementById("demo").innerHTML = text; </script>