JavaScript:switch结构

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>JavaScript:switch结构</title>

    <script>
        function isIntNum() {
            var x = document.getElementById("number").value;
            switch (x) {
                case "1":
                    console.dir("星期1");
                    break;//注解:如果没有break关键字会进入下一个case
                case "2":
                    console.dir("星期2");
                    break;
                default:
                    console.dir("放假");
                    break;
            }
        }
    </script>
</head>

<body>

<input type="text" id="number">
<button type="button" onclick="isIntNum()">点击这里</button>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/u013101178/article/details/81205626