<!DOCTYPE html> <html> <head> <title>浏览器对象</title> <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> </head> <body> <!--先编写好网页布局--> <h2>操作成功</h2> <span id="mysec" ></span> <span >秒后回到主页 </span> <a href="javascript:gback();">返回</a> <script type="text/javascript"> var sec=document.getElementById("mysec"); var i=5; function glocation() { if(i<1) { location.assign('http://www.imooc.com'); } sec.innerHTML=i; i--; } setInterval(glocation,1000); function gback() { history.go(-1) } </script> </body> </html>
解决方案:
var i=setInterval(glocation,1000);
在function glocation下加 clearInterval(i);