javascript - countdown.js 错误, "Uncaught ReferenceError: countdown is not defined"

标签 javascript jquery html

我正在尝试使用 Countdown.js 。我发现this guide并复制代码并粘贴它以尝试调整和理解代码,但是当我在 my web 中运行它时我无法让它工作,在控制台中我得到“Uncaught ReferenceError:倒计时未定义(匿名函数)@ countdown..html:46”。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="countdown.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<link rel="stylesheet" href="http://monopolo11.ninja/tests/css/main.css">
<link rel="stylesheet" type="text/css" href="flip/flipclock.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
</head>

<body>
    <div id="countdown-holder"></div>
    <script>
  var clock = document.getElementById("countdown-holder")
    , targetDate = new Date(2050, 00, 01); // Jan 1, 2050;

  clock.innerHTML = countdown(targetDate).toString();
  setInterval(function(){
    clock.innerHTML = countdown(targetDate).toString();
  }, 1000);
</script>
<br/>
<br/>
You will be logged out in <span id="logout-timer"></span>
<script>
  var timer = document.getElementById("logout-timer")
    , now = new Date()
    , deadline = new Date(now.getFullYear, now.getMonth, now.getDate, now.getHours, now.getMinutes + 15);

  timer.innerHTML = countdown(deadline).toString();
  setInterval(function(){
    timer.innerHTML = countdown(deadline ).toString();
  }, 1000);
</script>
</body>
</html>

最佳答案

指南使用countdown中的示例实际上应该是Countdown。

// Declare the countdown object
// Constructor. target_date and current_date are Javascript Date objects
function Countdown(target_date, current_date) {
    this.target_date = target_date;
    this.current_date = current_date;
}

关于javascript - countdown.js 错误, "Uncaught ReferenceError: countdown is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800294/

相关文章:

javascript - 如何处理 IOS Web 应用程序中的空 anchor

javascript - Angular Promise 使用多个 http 请求

javascript - jQuery 动态设置按钮元素事件和禁用

javascript - 单击一个 div 会更改附近 div 的位置

javascript - 如何在 jQuery 集合中获取被点击的项目索引?不是通过索引()

javascript - 如何针对倒数第二个 child 的 child ?

javascript - 如何使用按钮更改 Phantomjs 中的当前页面?

javascript - 链接到 id 但导航栏在路上

javascript - 降低鼠标速度

html - 将 HTML 表格转换为 R 数据框