Fix JQuery Countdown Timer in Rails 3 Application

前端 未结 1 1043
余生分开走
余生分开走 2021-02-11 11:46

I need a countdown timer for a rails application I\'m working on so I decided to use this.

http://keith-wood.name/countdown.html

In the public/javascripts folder

1条回答
  •  灰色年华
    2021-02-11 12:09

    Try wrapping

       var element = '#countDownTimer';
       var year = <%= @deal.end.year %>;
       var month = <%= @deal.end.month %>;
       var day = <%= @deal.end.day %>;
       setCountdownTimer(element, year, month, day);
    

    inside a $(document).ready()

    also I don't think this needs to be in the $(document).ready()

    function setCountdownTimer(element, year, month, day) {
      var date = new Date(year, month, day);
      $(element).countdown({until: date});
    }
    

    The issue is probably that your calling setCountdownTimer before its defined

    0 讨论(0)
提交回复
热议问题