无法在网站上获得JavaScript输出

时间:2016-04-16 22:37:58

标签: javascript html countdown

该网站应显示一个倒计时到纳税日的消息。我似乎无法在页面上显示任何内容。即使我输入了写代码,滚动条也不会显示颜色。请一些建议。

<!DOCTYPE HTML>
<html>
<head><meta charset="utf-8"> 
<title>TaxDay</title>
<script type="text/javascript">
<!-- Hide from old browsers

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


function countDown() {
 var today = new Date()
 var day of week = today.toLocaleString()
 dayLocate = dayofweek.indexOf(" ")
 weekDay = dayofweek.substring(0, dayLocate)
 newDay = dayofweek.substring(dayLocate)
 dateLocate = newday.indexOf(",")
 monthDate = newDay.substring(0, dateLocate+1)}
 yearLocate = dayofweek.indexOf("2016")
 year = dayofweek.substr(yearLocate, 4)

 var taxDate = new Date ("April 16, 2017")
 var daysToGo = taxDate.getTime()-today.getTime()
 var daysToTaxDate = Math.ceil(daysToGo/(1000*60*60*24))

function taxmessage() {
 var lastModDate = document.lastModified
 var lastModDate = lastModDate.substring(0,10)
 taxDay.innerHTML = "<p style='font-size:12pt; font-
 family:helvetica;'>Today is "+weekDay+" "+monthDate+" "+year+".
 You have "+daysToTaxDate+" days to file your taxes.</p>"
   }
 }
//-->
</script>           

<div> ID为taxDay,如果相关的话。正文onLoad事件处理程序为scrollColor(); countDown();taxmessage()

1 个答案:

答案 0 :(得分:0)

你没有在taxmessage()函数之前关闭countdown()函数 - 这意味着taxmessage嵌套在countdown()中。你也没有分号“;”在js的每一行之后。您应该重写代码以包含taxmessage()的函数或首先关闭countdown()并使用传递的参数调用taxmessage来获取日期变量。

检查控制台是否有错误