基于PHP和jQuery的倒数计时器? [英] Countdown timer built on PHP and jQuery?
问题描述
这里是我的情况;
PHP:
$ countdown = date(h:i :S); //这不是我实际的$ countdown变量,只是一个占位符
jQuery:
$(document).ready(function name(){
$(#this)。load(function(){
setTimeout( name(),1000)
}
}
});
HTML:
< div id =this><?php echo($ countdown);?><< ; / div>
我的想法是,每一秒, #this
重新加载,为它的内容赋予新的值,并且$ countdown不是一个静态变量,每次都会加载一个新的值,这样就不需要处理会话了(因为基本的JavaScript倒数计时器会在页面加载时重置,等等)。
我会虽然这会起作用,直到我意识到事件联编程序 .load()
不重新加载 #this
(我知道我很傻),所以我想我想知道的是 - 是否有一个事件联编程序,我可以使用这个工作要么有没有一种方法可以获得我所需要的功能,而无需使用jQuery插件(它完全不符合我想要的)?
您应该使用Keith Wood的倒数计时器: http://keith-wood.name/ countdown.html
非常容易使用。
所有你需要做的是
$ $ $ $('#c $ c $('#timer')。countdown({
until:'< ;?php回声日期(h:i:s); ?>'//改变它,显然是
});
这是小提琴: http://jsfiddle.net/tqyj4/289/
After spending the last 45 minutes looking around for a solution, I can't seem to find an easy solution to creating a countdown timer using PHP and jQuery. Most already built scripts I've found are based purely on jQuery which require a ton of code, and more parameters then they should, plus, adaptability is pretty hard.
Here's my situation;
PHP:
$countdown = date("h:i:s"); // This isn't my actual $countdown variable, just a placeholder
jQuery:
$(document).ready(function name() {
$("#this").load( function() {
setTimeout("name()", 1000)
}
}
});
HTML:
<div id="this"><?php echo($countdown); ?></div>
My idea is that, every second, #this
is reloaded, giving a new value to it's contents, and as $countdown isn't a static variable, a new value will be loaded each time. This removes the need to deal with sessions (as a basic javascript countdown timer would reset on pageload, etc).
I would've though this would have worked, until I realized that the event binder .load()
doesn't reload #this
(I know silly me), so I guess what I'm wondering is - is there an event binder I can use to make this work or is there a way to get the functionality I'm looking for, without using a jQuery plugin (which doesn't match exactly what I want anyway)?
You should use Keith Wood's countdown timer: http://keith-wood.name/countdown.html
It is extremely easy to use.
All you have to do is
$('#timer').countdown({
until: '<?php echo date("h:i:s"); ?>' // change this, obviously
});
Here's the fiddle: http://jsfiddle.net/tqyj4/289/
这篇关于基于PHP和jQuery的倒数计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!