簡體   English   中英

Javascript 不工作。 無輸出

[英]Javascript not working. No output

我正在嘗試完成的入門級 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>

有一大堆語法錯誤阻止瀏覽器執行您的 JavaScript。

如果你想看到這些,你可以使用瀏覽器的開發工具來找出它卡住的地方。

language屬性已被棄用很長時間,正如有人在此處鏈接(及其真實)中所說的那樣,因此您不必再將其放在那里,您應該將document.getElementById("output").innerHTML = output; 在您的 javascript 腳本中的所有內容下。

你有一個}

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

那是怎么回事?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM