在倒计时结束时隐藏一个div

Hide a div at the end of countdown

这是一个倒计时脚本,它运行正常。我想在倒计时结束时隐藏#mydiv。你能帮我做这个吗?

谢谢大家

<div data-countdown="2015/02/28 02:18:26"></div>

<script type="text/javascript">
 $('[data-countdown]').each(function() {
   var $this = $(this), finalDate = $(this).data('countdown');
   $this.countdown(finalDate, function(event) {     
   $this.html(event.strftime('%D gün %H:%M:%S'));
   });
 });
</script>

从 github 文档页面获取语法:

$this.countdown(finalDate)
    .on('update.countdown', function(event) { $this.html(event.strftime('%D gün %H:%M:%S')); })
    .on('finish.countdown', function() { $('#mydiv').hide(); });

http://api.jquery.com/hide/

http://hilios.github.io/jQuery.countdown/documentation.html

编辑: 刚刚注意到文档说:

Be aware thtat ALL events should be registered with the namespace *.countdown

<!DOCTYPE html>
<html>
<head>
    <title>jQuery countdown test</title>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://momentjs.com/downloads/moment.js"></script>
    <script src="http://cdn.rawgit.com/hilios/jQuery.countdown/2.0.4/dist/jquery.countdown.min.js"></script>
</head>

<body>
    <div id="divCountdown">test</div>

    <div id="mydiv">
        this div will be hidden in 10 seconds...
    </div>

    <script>
        $(document).ready(function () {
            var nowPlus30Seconds = moment().add('10', 'seconds').format('YYYY/MM/DD HH:mm:ss');

            $('#divCountdown').countdown(nowPlus30Seconds)
                              .on('update.countdown', function (event) { $(this).html(event.strftime('%D gün %H:%M:%S')); })
                              .on('finish.countdown', function () { $('#mydiv').hide(); });
        });
    </script>
</body>
</html>
    <script type="text/javascript">
 $('[data-countdown]').each(function() {
   var $this = $(this), finalDate = $(this).data('countdown');
   $this.countdown(finalDate, function(event) {     
   $this.html(event.strftime('%D gün %H:%M:%S'));
   $this.countdown(finalDate)
    .on('update.countdown', function(event) { $this.html(event.strftime('%D gün %H:%M:%S')); })
    .on('finish.countdown', function() { $('#selim').hide(); });
   });
 });
</script>

您可以使用这个简单的 javascript 和 jquery

<script>
$(document).ready(function () {
var nowPlus30Seconds = moment().add('10', 'seconds').format('YYYY/MM/DD HH:mm:ss');

$('.count1').countdown(nowPlus30Seconds)
.on('update.countdown', function (event) { $(this).html(event.strftime('%Y : %D : %H : %M : %S')); })
.on('finish.countdown', function () { $('#exp_div').hide(); });
});
</script>

完整代码和演示Here