js倒计时一分钟

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>count down</title>
</head>

<body>
<script type="text/javascript">
var seconds = 59;
var speed = 1000;
var span = document.createElement('span');
        document.body.appendChild(span);
function countDown(seconds,speed){
                var txt = "00 : " + ((seconds < 10) ? "0" + seconds : seconds) + " : 00";
                span.innerHTML = txt;
                var timeId = setTimeout("countDown(seconds--,speed)",speed);
                if(seconds == 0){
                        clearTimeout(timeId);
                };
}

countDown(seconds,speed);
</script>
</body>
</html>

posted @ 2015-06-16 14:00  会痛的-石头  阅读(3400)  评论(0编辑  收藏  举报