我真的只是复制了这个小提琴的完全相同的“代码”:https://jsfiddle.net/7b0ky186/到我的本地html-文件,而它周围没有其他东西。但是,虽然它在JSFiddle中运行得很好,但在我的控制台中启动该函数时,会出现一个错误,即Uncaught ReferenceError: CountDownTimer is not defined
我在那里做错了什么?
<body>
<a id="startTimer">Start Count Down</a>
<div>Registration schliesst in <span id="displayTimer"></span> minutes!</div>
<script type="text/javascript">
window.onload = function() {
var display = document.querySelector('#displayTimer'),
timer = new CountDownTimer(5),
timeObj = CountDownTimer.parse(5);
format(timeObj.minutes, timeObj.seconds);
timer.onTick(format);
document.querySelector('#startTimer').addEventListener('click', function() {
timer.start();
});
function format(minutes, seconds) {
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ':' + seconds;
}
};
</script>发布于 2021-02-20 21:36:16
在jsFiddle.org的左侧,您可以看到"Resources 1“。您可以点击它,它将显示所有添加的“资源”。然后,您可以从那里复制链接。在这种情况下,您需要countdowntimer.js

当您拥有缺少的.js的URL时,可以在<script>标记之前添加它,就像这样
<!-- your HTML goes here -->
<script src="https://cdn.rawgit.com/robbmj/simple-js-countdown-timer/master/countdowntimer.js"></script>
<!-- your <script> and js things go here -->https://stackoverflow.com/questions/66296775
复制相似问题