js倒计时

    $(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);

    });   
posted @ 2015-08-04 11:35  微客鸟窝  阅读(148)  评论(0编辑  收藏  举报
/* 看板娘 */