<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>8-17编程练习</title> </head> <body> <!--先编写好网页布局--> <div id="hint"> <h2>操作成功</h2> <span><b id="second"></b>前往慕课网<a href="javascript:void(0)" onclick="window.history.back()">返回</a></span> </div> <button id="skbut" onclick="skip()">前往慕课网</button> <script language="javascript" type="text/javascript"> var hint = document.getElementById("hint"); hint.style.display = "none"; var skbut = document.getElementById("skbut"); skbut.style.display = "block"; skbut.style.cursor = "pointer"; var second = 5; function sum(){ second--; document.getElementById("second").innerHTML = second; if(second > 0){ setTimeout(sum,1000); }else{ clearTimeout; } }; function window_(){ window.open('https://www.imooc.com/','_self'); } function skip(){ if(hint.style.display == "none"){ hint.style.display = "block"; skbut.style.display = "none"; }; document.getElementById("second").innerHTML = second; setTimeout(sum,1000); setTimeout(window_,5000); }; </script> </body> </html>
44行优化一下改为 setTimeout(window_,second*1000);
emmmm,想法不错,操作体验感觉挺棒的.特别是加了一个前往按钮
有点难