首页 > 解决方案 > hilios javascript倒计时完成后不会触发回调

问题描述

我在同一页面上有多个倒计时。并且这个脚本是根据单次倒计时修改的。<time>所以我需要它来触发标签上的每个完成事件的警报。但我不知道为什么它最后没有警觉。请帮帮我。

$('[data-countdown]').each(function() {
  var $this = $(this),
    finalDate = $(this).data('countdown');
  $this.countdown(finalDate, function(event) {
    var format = '%H:%M:%S';
    $(this).html(event.strftime(format));
  }).on('finish.countdown', function() {
    alert('time up!');
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/hilios/jQuery.countdown/2.2.0/dist/jquery.countdown.min.js"></script>

<time data-countdown="2021/07/28 10:28:40"></time>
<br />
<time data-countdown="2021/07/28 12:08:00"></time>
<br />
<time data-countdown="2021/07/29 00:00:00"></time>
您可以尝试在此处更改小提琴中最近的完成时间:https ://jsfiddle.net/ayonsd5h/2/

标签: javascripthtml

解决方案


推荐阅读