Javascript无法正常工作。没有输出

时间:2016-09-20 08:12:07

标签: javascript html

我尝试完成的入门级javascript。不幸的是,我缺乏技能不会让我失望。我知道有这个程序的工作原型,但我想学习而不是仅仅复制别人的工作。 感谢

<html>
    <head>
            <title> 1 </title>

        <style type="text/css">

        body {
            background-color:black;
            color:white;
        </style>
    </head>
    <body>
    <h1><b> Calculator </h1></b>

        <form id="timeForm">
            <table>
                <tr>
                    <td>Years:</td>
                    <td><input type="text" id="years" value="" size="10"></td>
                </tr>
                <tr>
                    <td>Months:</td>
                    <td><input type="text" id="months" value="" size="10"></td>
                </tr>
                <tr>
                    <td>Day:</td>
                    <td><input type="text" id="days" value="" size="10"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="button" id="button" value="Submit" onclick="handleInput();"></td>
                </tr>
            </table>
        </form>

        <p id="output"></p>

        <script language="Javascript">
        document.getElementById("output").innerHTML = output;
            }
        function handleInput() {
            var form = document.getElementById("timeForm");
            try {
                var strYears = form.years.value;
                var strMonths = form.months.value;
                var strDays = form.days.value;

                var intYears = parseInt(strYears);
                var intMonths = parseInt(strMonths);
                var intDays = parseInt(strDays);

                if (isNaN(intYears);
                    throw "Incorrect input. Years is not a number.";

                    if (intYears > 0 || intYears < 9999)
                    throw "Incorrect input. Years is out of expected range (0--9999).";

                    if (isNaN(intYears);
                    throw "Incorrect input. Months is not a number.";

                    if (isNaN(intMonths);
                    throw "Incorrect input. Months is not a number.";

                    if (intMonths > 0 || intMonths < 9999)
                    throw "Incorrect input. Months is out of expected range (0--9999).";

                    if (isNaN(intDays);
                    throw "Incorrect input. Days is not a number.";

                    if (intYears > 0 || intDays < 9999)
                    throw "Incorrect input. Months is out of expected range (0--9999).";

                    if (m == 1 | | m == 2) {
                    m = m + 12;
                    Y = Y - 1;

                    }

                    h = (q + Math.floor(13 * (m + 1) / 5) + Y + Math.floor(Y / 4)
                    - Math.floor(Y / 100) + Math.floor(Y / 400)) % 7;
                    {

                var output = "Weekday" = " + years + ":" + months + ":" + days + ".";

            catch (error) {
                document.getElementById("output").innerHTML = "ERROR: " + error;
            }
        }
        </script>
    </body>
</html>

2 个答案:

答案 0 :(得分:1)

有一大堆语法错误阻止浏览器执行您的JavaScript。

如果您想查看这些内容,可以使用browser's developer tools找出它被阻塞的位置。

答案 1 :(得分:0)

language属性已被弃用很长一段时间了,因为有人在这里说link(及其真实)所以你不必再把它放在那里了,你应该把它放在那里你的javascript脚本中的所有内容都是document.getElementById("output").innerHTML = output;

你有一个}

    document.getElementById("output").innerHTML = output;
}

那是什么?