<script>var num = document.getElementById("second");var counter = num.innerHTML;function count(){counter--;num.innerHTML=counter;if(counter==0){window.location.assign("http//:www.imooc.com");}}setInterval("count()",1000);function back(){window.history.back();}</script><h1>操作成功</h1><span id="second">5</span><span>秒后回到主页</span><input type="button" value="返回" onclick="back()">
1 回答

业余奶茶品鉴师
TA贡献260条经验 获得超388个赞
把js写到html后面就可以了,是渲染先后的问题,按照你的写法document.getElementById("decond")取不到
按照下面那这样写就可以了,记得采纳
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=<device-width>, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { padding: 0; margin: 0; } </style> </head> <body> <h1>操作成功</h1> <span id="second">5</span> <span>秒后回到主页</span> <input type="button" value="返回" onclick="back()"> </body> <script> var num = document.getElementById("second"); var counter = num.innerHTML; function count() { counter--; num.innerHTML = counter; if (counter == 0) { window.location.assign("http//:www.imooc.com"); } } setInterval("count()", 1000); function back() { window.history.back(); } </script> </html>
添加回答
举报
0/150
提交
取消