hilios javascript 倒数计时器完成事件磨损初始化
hilios javascript countdown timer finish event worn initialize
我正在使用这个 javascript countdown plugin 并且我想检测完成日期,这是我的设置以及到目前为止我已经尝试过的设置。
$('#countdown').countdown('2015/11/12', function(event) {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
}).on('finish.countdown', function(event){
alert("the event is finish");
});
但似乎不起作用,有什么想法,请帮忙?
您正在使用 'legacy approach',正如 the documentation 所说:
With the legacy approach you will need to handle all events in a
single callback (update, finish or stop) through the event.type
property
您应该使用更新的方法:
$('#countdown').countdown('2015/11/12')
.on('update.countdown', function(e) {
$(this).html(e.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
})
.on('finish.countdown', function(e) {
alert("the event is finish");
});
或者如果您仍想使用旧语法:
$('#countdown').countdown('2015/11/12', function(event) {
if (event.type === 'update.countdown') {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
} else if (event.type === 'finish.countdown') {
alert("the event is finish");
});
我正在使用这个 javascript countdown plugin 并且我想检测完成日期,这是我的设置以及到目前为止我已经尝试过的设置。
$('#countdown').countdown('2015/11/12', function(event) {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
}).on('finish.countdown', function(event){
alert("the event is finish");
});
但似乎不起作用,有什么想法,请帮忙?
您正在使用 'legacy approach',正如 the documentation 所说:
With the legacy approach you will need to handle all events in a single callback (update, finish or stop) through the event.type property
您应该使用更新的方法:
$('#countdown').countdown('2015/11/12')
.on('update.countdown', function(e) {
$(this).html(e.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
})
.on('finish.countdown', function(e) {
alert("the event is finish");
});
或者如果您仍想使用旧语法:
$('#countdown').countdown('2015/11/12', function(event) {
if (event.type === 'update.countdown') {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
} else if (event.type === 'finish.countdown') {
alert("the event is finish");
});