JavaScript实例:输入数字输出星期几

代码实现(代码中已注释)

<html>
<head>
    <script language="javascript">
        function change(x) {
            if (x == 0) { document.write("星期日"); } 
            else if (x == 1) { document.write("星期一"); }
            else if (x == 2) { document.write("星期二"); }
            else if (x == 3) { document.write("星期三"); }
            else if (x == 4) { document.write("星期四"); }
            else if (x == 5) { document.write("星期五"); }
            else if (x == 6) { document.write("星期六"); }
            else { document.write("输入的数字不正确"); }
        }
    </script>
</head>
<body>输入一个0-6的阿拉伯数字:<input id="Text1" type="text" />
    <input type="button" id="Button1" value="button" onclick="javascript:change(document.getElementById('Text1').value);" />
</body>
</html>

运行结果

猜你喜欢

转载自blog.csdn.net/m0_54158068/article/details/124699860