一段最简单的实现HTML页面上倒计时的动态效果

<html>
<script>
var countdown = function(timeout) {
    var countUI = document.getElementById("count");
    if(!!countUI) {
        countUI.innerHTML = timeout;
        if (timeout == 0) {
            alert("end");
        }
        else {
        	timeout--;
            setTimeout(function(){ 
            	countdown(timeout)
            }, 1000);
        }
    }
}

function init(){
	countdown(5);
}
</script>
<body onload=init();>
<div id="count">5</div>
</body>
</html>
发布了7153 篇原创文章 · 获赞 654 · 访问量 122万+

猜你喜欢

转载自blog.csdn.net/i042416/article/details/105013479
今日推荐