简体   繁体   English

javascript 不会执行函数

[英]javascript won't execute functions

I have the following code written that should do the following: - Create a dynamic message with a countdown - Change the scrollbar color (use #20409a for the scroll bar face color and #ffde20 for the scroll bar track color) - Use the selected index in the select tag to link to new webpages - Add URL, copyright notice, date the Webpage was last modified我编写了以下代码,应该执行以下操作: - 创建一个带有倒计时的动态消息 - 更改滚动条颜色(使用 #20409a 作为滚动条表面颜色和 #ffde20 作为滚动条轨道颜色) - 使用选定的索引在链接到新网页的选择标签中 - 添加 URL、版权声明、网页上次修改日期

However when I launch the website I get a standard webpage, what am I doing wrong or have I missed.然而,当我启动网站时,我得到了一个标准网页,我做错了什么或我错过了什么。 Thanks for your help.谢谢你的帮助。

<!DOCTYPE HTML>

<html>
    <head>
        <meta charset="utf-8">
        <title>Unit 4 - A2</title>
        <script type="text/javascript">
            function countDown() {
                var today = new Date()                              // Obtain current system date
                var dayofweek = today.toLocaleString()              // Convert date to a string that can be manipulated  Day, Month Date, Year HH:MM:SS AM/PM

                dayLocate = dayofweek.indexOf(" ")                  // Use indexOF() method to find the space between the month and day of the week to extract the month
                weekDay = dayofweek.substring(0, dayLocate)         // Use substring method to extract the day of the week from the string
                newDay = dayofweek.substring(dayLocate)             // Use substring to extract the remainder of the date from the strong
                dateLocate = newDay.indexOf(",")                    // 
                monthDate = newDay.substring(0, dateLocate + 1)
                yearLocate = dayofweek.indexOf("2015")
                year = dayofweek.substr(yearLocate, 4)

                var DateOfLaunch = new Date("July 31, 2015")
                var daysToGo = DateOfLaunch.getTime()-today.getTime()
                var daysToLaunch = Math.ceil(daysToGo/(1000*60*60*24))
            }

            function scrollColor() {
                styleObject = document.getElementsByTagName('html')[0].style
                styleObject.scrollbarFaceColor = "#20409a"
                styleObject.scrollbarTrackColor = "#ffde20"
            }

            function loadInfo(myForm) {
                var menuSelect = myForm.Menu.selectedIndex
                var menuUrl = myForm.Menu.options[menuSelect].value + ".html"
                window.location = menuUrl
            }

            funtion copyRight () {
                var lastModDate = document.lastModified
                var lastModDate = lastModDate.substring(0,10)

                displayCopyRight.innerHTML = "<h6>The URL of this document is" + document.URL + "<br />Copyright Smart Homes System<br />This document was last modified " + lastModDate + ".</h6>"
            }
        </script>
        <style type="text/css">
            .center {
                text-align: center;
            }

            table {
                margin-left: 15%;
                margin-right: 15%;
            }

            .cell-width {
                width: 50%;
            }

            .left-align {
                width: 50%;
                left: 0px;
            }

            .right-align {
                width: 50%;
                right: 0px;
                text-align: right;
            }

            .smallprint {
                "Times New Roman", Times, serif;
                font-weight: bold;
            }

            .textheadings {
                font-weight: bold;
            }
        </style>
    </head>

    <body>
        <div class="center">
            <p><img src="banner-product.jpg" alt="Smart Homes, Inc banner"></p>
            <p style="font-weight: bold;">About the Smart Homes System</p>
                <img src="hrimg.gif" width="750px" height="5px" alt="hr line">
        </div>
        <div id=displayDate>
        </div>
        <table>
            <tr>
                <td colspan="2">
                    <p style="font-weight: bold;">The Smart Homes System</p>
                    <p>Smart Homes is an innovative home thermostat learns the usage patterns of its home's occupants over time and uses the data it collects to program itself to save money and energy. Additionally, the product allows owners to remotely control and program the thermostat via mobile computing devices such as Apple's iPhone and Google's Android.</p>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <form id="announceMenu" action=" ">
                        <p style="font-weight: bolder;">Select an item from the list to see other current announcements:
                            <select name="Menu" onchange="loadInfo(this.form)">
                                <option>Select an item</option>
                                <option value="products">Products</option>
                                <option value="tickets">Prices</option>
                                <option value="listings">Features</option>
                                <option value="locations">Retail Locations</option>
                            </select>
                        </p>
                    </form>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p style="font-weight: bold;">Installation Guide</p>
                    <p>Smart Homes technology is easy to install! Detailed instruction.</p>
                </td>
            </tr>
            <tr>
                <td class="right-align">
                    <img src="image.jpg" alt="title" width="321px" height="160px">
                </td>
                <td class="left-align">
                    <img src="image2.jpg" alt="title" width="246px" height="161px">
                </td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
        </table>
        <div id="displayCopyRight">
        </div>
    </body>
</html>

You have only defined the functions, you never call them.您只定义了函数,从未调用过它们。 You need to call the functions to execute them.您需要调用函数来执行它们。

I also would suggest moving your entire script to down just before the /body tag.我还建议将整个script移到/body标签之前。

So, like this:所以,像这样:

        <div id="displayCopyRight">
        </div>

        <script>
            // your other JS code goes here...

            countDown();
            scrollColor();
            loadInfo();
            copyRight();
        </script>
    </body>
</html>

You have made a spelling mistake of "function".您在“函数”方面犯了一个拼写错误。 By mistake you have written "funtion".你错误地写了“函数”。 Correct it.纠正它。

function copyRight () {
            var lastModDate = document.lastModified
            var lastModDate = lastModDate.substring(0,10)

            displayCopyRight.innerHTML = "<h6>The URL of this document is" + document.URL + "<br />Copyright Smart Homes System<br />This document was last modified " + lastModDate + ".</h6>"
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM