<!doctype html> <html> <head> <meta charset="utf-8"> <title>制作一个跳转提示页面</title> </head> <body> <p>操作成功</p> <p><span id="txt">5</span>秒后回到主页 <a href="javascript:GoBack()">返回</a></p> <script type="text/javascript"> var num=5; function clock(){ if(num>1){ num=num-1; document.getElementById("txt").innerHTML=num; setTimeout(clock,1000); } else{ location.href("http://www.imooc.com/"); } } setTimeout(clock,1000); function GoBack(){ window.history.back(); } </script> </body> </html>
location.href 是属性,而不是方法。
所以第20行改为:
location.href = "http://www.php.cn/";