jQuery简单美观的秒倒计时代码

jQuery简单美观的秒倒计时代码

jQuery简单美观的秒倒计时代码

一款简单美观的jQuery秒倒计时代码,精确到毫秒,自定义时间秒数点击开始按钮开始倒计时,点击重置按钮重新开始。

源码介绍

js代码

"text/javascript" src="js/jquery-1.8.3.min.js"
"text/javascript"> 
    function timeout(obj){ 
        if(obj<10){ 
 
        }else{ 
            var times = obj * 100// 60秒 
            countTime = setInterval(function() { 
                times = --times < 0 ? 0 : times; 
                var ms = Math.floor(times / 100).toString(); 
 
                if(ms.length <= 1{ 
                    ms = "0" + ms; 
                } 
                var hm = Math.floor(times % 100).toString(); 
                if(hm.length <= 1{ 
                    hm = "0" + hm; 
                } 
                if(times == 0{ 
                    //alert("游戏结束"); 
                    clearInterval(countTime); 
                } 
                // 获取分钟、毫秒数 
                $(".a").html(ms); 
                $(".b").html(hm); 
            }10); 
        } 
 
         
    } 
    $(function () { 
        $('.start').click(function () { 
            var a = $('.a').html(); 
            timeout(a); 
        }
        $('.end').click(function () { 
            $('.a').html(10); 
            $('.b').html('00'); 
            clearInterval(countTime); 
        }
    }


分享到 :

发表评论

登录... 后才能评论