在Rails 3应用程序中修复JQuery倒数计时器 [英] Fix JQuery Countdown Timer in Rails 3 Application
问题描述
我需要一个正在工作的Rails应用程序的倒数计时器,所以我决定使用它.
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
在public/javascripts文件夹中,我添加了jquery.countdown.js 在public/styleheets文件夹中,我添加了jquery.countdown.css
In the public/javascripts folder I've added jquery.countdown.js In the public/styleheets folder I've added jquery.countdown.css
在app/views/layouts/application.html.erb中,我将javascript和css文件添加到样式表和javascript标签中.
In app/views/layouts/application.html.erb I add the javascript and css files to the stylesheet and javascript tags.
我认为我已添加
<script>
var element = '#countDownTimer';
var year = <%= @deal.end.year %>;
var month = <%= @deal.end.month %>;
var day = <%= @deal.end.day %>;
setCountdownTimer(element, year, month, day);
</script>
<div id="countDownTimer"></div>
这将用于与jQuery选择以添加计时器.
which is going to be used to select with jQuery to add the timer.
这是我的application.js文件
Here is my application.js file
// The following function is called once the rest of the document is fully loaded
$(document).ready(function()
{
function setCountdownTimer(element, year, month, day) {
var date = new Date(year, month, day);
$(element).countdown({until: date});
}
// DEALS TABS ON DEALS PAGES
$("#tabs > ul").tabs(); // Make the tabs.
// FANCYBOX FOR GALLERY IMAGES POPUP
$("a.galleryitem").fancybox();
// MEDIA ENCODER FOR PODCASTS
$.mb_audioEmbedder.playerPath="/media/player.swf" //the path to audio player
$.mb_videoEmbedder.defaults.width=500;
$.mb_audioEmbedder.defaults.width=214;
$("#media").mb_embedMovies();
$("#media").mb_embedAudio();
});
谁能告诉我为什么这行不通?
Can anyone tell me why this doesn't work?
推荐答案
尝试包装
var element = '#countDownTimer';
var year = <%= @deal.end.year %>;
var month = <%= @deal.end.month %>;
var day = <%= @deal.end.day %>;
setCountdownTimer(element, year, month, day);
在$(document).ready()
我也不认为这需要放在$(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});
}
问题可能是您在定义setCountdownTimer之前调用了
The issue is probably that your calling setCountdownTimer before its defined
这篇关于在Rails 3应用程序中修复JQuery倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!