用setInterval完成倒计时
<body onload="timerb()"> <h3>操作成功</h3> <p id="p1"></p> <script> var num = 5; var timer = null; function timerb() { document.getElementById('p1').innerHTML = num + '秒后跳到首页' num--; if (!timer) { timer = setInterval("timerb()", 1000) } if (num === 0) { timer = null; location.replace('http://www.baidu.com') } } </script> </body>