Uncaught TypeError: $(...).countdown is not a function``` when using jcountdown via rails-assets-pipeline
Uncaught TypeError: $(...).countdown is not a function``` when using jcountdown via rails-assets-pipeline
我在通过 rails-assets-pipeline
使用 jcountdown 时在页面中显示计时器时遇到问题
Error message: Uncaught TypeError: $(...).countdown is not a function
代码:
countdown_timer.js
$(document).ready(function(){
$("#timeleft").countdown({
"date" : "november 07, 2015"
});
});
查看:
<div id="timeleft"></div>
我理解这个错误,但对 javascript 了解不多,所以我不知道如何修复它。我正在按照他们的维基页面 jcountdown
的说明进行操作
我从 application.js
和 application.scss
中删除了 //= (*=)require jcountdown
因为 unable to find stylesheets using turboliks
既然我们已经成功加载了库,
替换
$(document).ready(function() {
$("#timeleft").countdown({
"date" : "november 07, 2015"
});
});
和
$(document).ready(function() {
$("#timeleft").countdown("2015/11/07");
});
有关更多信息,我会参考最新版本的文档 here
编辑:
页面上也给出了一个简单的例子,但我会在这里重复。
html
<div id="getting-started"></div>
和 js
$("#getting-started")
.countdown("2016/01/01", function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
我加了
<script src="js/jquery.countdown.js"></script>
到 body 的最后一行,它起作用了。这是因为我的页面没有加载这个 js。
检查您应该存储在服务器上的所有脚本文件。如果缺少任何内容,您将收到上述错误。修好了我的。
<script src="[path]/jquery.countdown.min.js"></script>
访问 link https://[path]/jquery.countdown.min.js
以确保可以找到该文件
我在通过 rails-assets-pipeline
Error message: Uncaught TypeError: $(...).countdown is not a function
代码:
countdown_timer.js
$(document).ready(function(){
$("#timeleft").countdown({
"date" : "november 07, 2015"
});
});
查看:
<div id="timeleft"></div>
我理解这个错误,但对 javascript 了解不多,所以我不知道如何修复它。我正在按照他们的维基页面 jcountdown
的说明进行操作我从 application.js
和 application.scss
中删除了 //= (*=)require jcountdown
因为 unable to find stylesheets using turboliks
既然我们已经成功加载了库,
替换
$(document).ready(function() {
$("#timeleft").countdown({
"date" : "november 07, 2015"
});
});
和
$(document).ready(function() {
$("#timeleft").countdown("2015/11/07");
});
有关更多信息,我会参考最新版本的文档 here
编辑:
页面上也给出了一个简单的例子,但我会在这里重复。
html
<div id="getting-started"></div>
和 js
$("#getting-started")
.countdown("2016/01/01", function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
我加了
<script src="js/jquery.countdown.js"></script>
到 body 的最后一行,它起作用了。这是因为我的页面没有加载这个 js。
检查您应该存储在服务器上的所有脚本文件。如果缺少任何内容,您将收到上述错误。修好了我的。
<script src="[path]/jquery.countdown.min.js"></script>
访问 link https://[path]/jquery.countdown.min.js
以确保可以找到该文件