我编写了以下代码,应该执行以下操作: - 使用倒计时创建动态消息 - 更改滚动条颜色(使用#20409a作为滚动条面颜色和 #ffde20用于滚动条轨道颜色) - 使用select标记中的选定索引链接到新网页 - 添加网址,版权声明,上次修改网页的日期
然而,当我启动网站时,我得到一个标准网页,我做错了什么或者我错过了什么。谢谢你的帮助。
<!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"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
<div id="displayCopyRight">
</div>
</body>
</html>
答案 0 :(得分:1)
您只定义了这些功能,从不调用它们。您需要调用函数来执行它们。
我还建议将整个script
移到/body
标记之前。
所以,就像这样:
<div id="displayCopyRight">
</div>
<script>
// your other JS code goes here...
countDown();
scrollColor();
loadInfo();
copyRight();
</script>
</body>
</html>
答案 1 :(得分:0)
你犯了#34; function&#34;的拼写错误。你错误地写了&#34; funtion&#34;。纠正它。
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>"
}