Fix JQuery Countdown Timer in Rails 3 Application

前端 未结 1 2063
迷失自我
迷失自我 2021-02-11 11:45

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条回答
  •  -上瘾入骨i
    2021-02-11 12:11

    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)
提交回复
热议问题