码迷,mamicode.com
首页 > Web开发 > 详细

js倒计时

时间:2015-08-04 12:51:00      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

    $(window).load(function(){                         
        var t = setInterval(function(){
            
            var n = Date.parse(new Date())/1000;
            $(".sc4 #timeout").each(function(){
                var self = this;
                var y = $(this).attr(‘time‘);
                var m = y*1+1800*1;
                var d = m - n;
                var s = d%60;            //取余(秒)
                var i = (d-s)/60;  //取整(分)
                if(d <= 0){
                    $(this).text(0);
                    var tnumber = $(this).attr(‘tnumber‘);
                    $.ajax({
                        url:‘/Home/Tao/timeout‘,
                        type:‘POST‘,
                        datatype:‘json‘,
                        data:{number:tnumber},
                        success:function(data){
                            if(data == 1){
                                $.dialog({content:‘time is out!‘,ok:function(){}});
                                $(self).parentsUntil(‘.sc4‘).css(‘background‘,‘#FACDC4‘).animate({opacity: ‘hide‘}, 1000);
                                setTimeout(function(){ $(self).parentsUntil(‘.sc4‘).remove();},1000);
                            }
                        }
                    });
                }else{
                    $(this).text(i+"分"+s+"秒");
                }
                

            });

        },1000);

    });   

js倒计时

标签:

原文地址:http://www.cnblogs.com/isungge/p/4701561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!