js实现倒计时和jquery实现倒计时

jquery实现倒计时代码:

<script src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
var i=5;
$(function(){
    setTimeout(function(){
        window.location.href='';
    },5000);
    freshen();
});
//自动刷新页面上的时间
function freshen(){
    $("#time").empty().append(i);
    i=i-1;
    setTimeout(function(){
        freshen();
    },1000);
}
</script>

js实现倒计时代码:

(function () {
    var wait = document.getElementById('time'),
        href = document.getElementById('linkName').href;
    var interval = setInterval(function () {
        var time = --wait.innerHTML;
        if (time <= 0) {
            location.href = href;
            clearInterval(interval);
        }
        ;
    }, 1000);
})();

猜你喜欢

转载自blog.csdn.net/diaoweixiao/article/details/80800597