我正在尝试创建一个简单的3-2-1倒计时器。我想显示3、2和1,并在倒计时结束时运行一个函数。我尝试了一些方法,但都没有成功:
$("#count_num").delay(1000).queue(function() {
$(this).html("2")
});
$("#count_num").delay(1000).queue(function() {
$(this).html("1")
});
并且:
$("#count_num").delay(1000).queue(function() {
$(this).html("2").delay(1000).queue(function() {
$(this).html("1")
});
});
在这些情况下,它确实会到达2,但从不到达1。我还安装了doTimeout插件(http://benalman.com/projects/jquery-dotimeout-plugin/)并尝试了以下操作:
$.doTimeout( 1000, function(){
$("#count_num").html("2");
});
$.doTimeout( 1000, function(){
$("#count_num").html("1");
});
并且:
var count=3;
$.doTimeout( 1000, function(){
if ( count==1 ) {
// do something finally
return false;
}
$("#count_num").html(count);
count--;
return true;
});
我做错了什么?谢谢。
handleTimer
加了一个参数,但它不应该有参数。现在请尝试(更新后的答案)。 - EMMERICH