2015-06-28 2 views
-2

У меня есть следующий код, написанный, что необходимо сделать следующее: - Создание динамического сообщение с обратным отсчетом - Изменение цвета полосы прокрутки (использование # 20409a для цвета полосы прокрутки лица и # ffde20 для цвета полосы прокрутки) - использовать выбранный индекс в выберите тег для ссылки на новые веб-страниц - Добавить URL, уведомление об авторских правах, дату веб-странице Последнее изменениеJavascript не будет выполнять функции

Однако, когда я запускаю сайт, я получаю стандарт веб-страница, что я делаю неправильно или я пропустил. Спасибо за вашу помощь.

<!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> 
+2

Вы проверили консоль браузера на наличие ошибок? – Pointy

+1

Вы фактически не вызываете эти функции нигде. Где/когда/как вы ожидаете их исполнения? – David

ответ

1

Вы определили только функции, которые вы никогда не называете. Вам нужно вызвать функции для их выполнения.

Я также предлагаю переместить весь ваш script вниз перед тегом /body.

Так, например:

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

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

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

Спасибо за вашу помощь ... Я беру курс в JavaScript и следую коду из книги для занятий. Он показал мне шаг за шагом через выше, так как можно вызвать эти функции, чтобы они работали правильно? Я думал, что все правильно настроил в соответствии с книгой ... однако именно поэтому я спрашиваю экспертов, а не моего профессора (потому что он выбрал книгу) –

+0

Вы вызываете функцию, используя имя функции и круглые скобки. Проверьте код, который я включил в свой ответ ... эти четыре строки, начинающиеся с 'countDown()', являются вызовами функций. – dgrundel

+0

Вау ... это все, что я должен был добавить? Это казалось таким простым ... он никогда не показывал это нигде в книге. Спасибо за вашу помощь. –

0

Вы сделали орфографическую ошибку "функции". По ошибке вы написали «funtion». Исправь это.

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>" 
     } 
+0

Спасибо ... Я исправил опечатку. –

Смежные вопросы