js 实现5秒倒计时后跳转页面

<script type="text/javascript">
        function countDown(secs, surl) {
            var jumpTo = document.getElementById('jumpTo');
            jumpTo.innerHTML = secs;
            if (--secs > 0) {
                setTimeout("countDown(" + secs + ",'" + surl + "')", 1000);
            }
            else {
                location.href = surl;
            }
        }     
    </script>

使用方法:

<div>
        <h2>
            发生错误,<span id="jumpTo">5</span>秒后自动跳转到首页,返回后请联系客服!</h2>
    </div>
    <script type="text/javascript">        countDown(5, '/default.aspx');</script>

 

posted @ 2014-01-03 15:58  PandaIT  阅读(4148)  评论(0编辑  收藏  举报