未捕获的语法错误与日倒计时脚本

Uncaught SyntaxError with day countdown script

本文关键字:倒计时 脚本 错误 语法      更新时间:2023-09-26

所以我有这个脚本,我从一个网站上得到的,我尽我有限的JS知识对其进行了修改。令人惊讶的是,它不起作用,因为它在我将突出显示的行上给出了一个错误。这是我放在HTML中的脚本:

<script>
  var before = "Event before"
  var current = "Today is the date set in countdown"
  var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
  function countdown(yr, m, d) {
      var today = new Date()
      var todayy = today.getYear()
      if (todayy < 1000)
        todayy += 1900
      var todaym = today.getMonth()
      var todayd = today.getDate()
      var todaystring = montharray[todaym] + " " + todayd + ", " + todayy
      var futurestring = montharray[m - 1] + " " + d + ", " + yr
      var difference = (Math.round((Date.parse(futurestring) - Date.parse(todaystring)) / (24 * 60 * 60 * 1000)) * 1)
      if (difference == 0)
        document.getElementByID("days").innerHTML = "0";
      else if (difference > 0)
        document.getElementByID("days").innerHTML = +difference + ;
    }
    //enter the count down date using the format year/month/day
  countdown(2015, 01, 01)
</script>

它应该替换段落中粗体标签的内容,但显然问题出在实际脚本上,而不是 ID 或函数上。

任何帮助都非常感谢:)

else if (difference > 0)
    document.getElementByID("days").innerHTML = difference;