【问题标题】:Ruby on Rails - jQuery.countdown no displayRuby on Rails - jQuery.countdown 不显示
【发布时间】:2014-09-25 21:24:24
【问题描述】:

在我搬到 RoR 之前,我使用了这个很棒的 jQuery countdown,它运行良好。 我尝试在我的 Rails (4.0.8) 应用程序中再次使用它,但我不明白为什么什么都没有显示。

我在 app/assets/javascripts 中(以及其他):

application.js
jquery.countdown.min.js
jquery-2.1.1.min.js

在我的 application.js 中:

//= require_tree .
//= require jquery-2.1.1.min
//= require jquery.countdown.min

在我的 Gemfile 中:

gem 'jquery-rails', '3.0.4'

在我的 app/views/pages/page.html.erb 中:

<br />
--
<div data-countdown="2016/01/01"></div>
--

<script type="text/javascript">
  $('[data-countdown]').each(function() {
   var $this = $(this), finalDate = $(this).data('countdown');
   $this.countdown(finalDate, function(event) {
     $this.html(event.strftime('%D days %H:%M:%S'));
   });
 });
</script>

喜欢documented on this page,但什么也没显示。

我是否遗漏了一些明显的东西?感谢您的帮助。

【问题讨论】:

    标签: jquery ruby-on-rails countdown jquery-countdown


    【解决方案1】:

    我设法再次显示我的倒计时!

    我发现(打印 javascript 控制台)我有错误 $ is not defined。所以我从我的 Gemfile 中删除 gem 'jquery-rails', '3.0.4' 并执行命令 gem uninstall jquery-rails。然后我在标题中添加了这几行并重新启动了服务器。

    <%= javascript_include_tag "jquery-2.1.1.min" %>
    <%= javascript_include_tag "jquery.countdown.min" %>
    

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 2015-03-03
      • 2014-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 2018-11-19
      • 2017-04-08
      相关资源
      最近更新 更多