JS倒计时10秒
<div id="cnblogs_post_body">1、<html><head><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;><title>counter</title><script language=&quot;javascript&quot; type=&quot;text/JavaScript&quot;> function Counter(nMax, nInterval) { this.maxTime = nMax; this.interval = nInterval; this.objId = &quot;timer&quot;; this.obj = null; this.num = this.maxTime; this.timer = null; this.start = function() { this.obj = document.getElementById(this.objId); if (this.num > 0) setTimeout(this.run, this.interval * 1000); }; this.run = function() { if (myCounter.num > 0) { myCounter.num--; myCounter.obj.innerHTML = myCounter.num; myCounter.timer = setTimeout(myCounter.run, myCounter.interval * 1000); } else clearTimeout(myCounter.timer); }; this.show = function() { document.write(&quot;<span id=&quot;+this.objId+&quot;>&quot; + this.num + &quot;</span>&quot;); this.obj = document.getElementById(this.objId); //alert(this.obj.innerHTML); } }</script></head><body onload=&quot;myCounter.start();&quot;> <script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;> var myCounter = new Counter(10, 1); </script> <p> 现在剩下 <script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;> myCounter.show(); </script> 秒钟! </p></body></html> 2、 请等待<span id=&quot;dd&quot;>10</span>秒<script type=&quot;text/javascript&quot;> function run() { var s = document.getElementById(&quot;dd&quot;); if (s.innerHTML == 0) { window.location.href = 'regform.shtml'; return false; } s.innerHTML = s.innerHTML * 1 - 1; } window.setInterval(&quot;run();&quot;, 1000);</script>.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; } 3、 <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;><script type=&quot;text/javascript&quot;><!-- var duration = 9900; var endTime = new Date().getTime() + duration + 100; function interval() { var n = (endTime - new Date().getTime()) / 1000; if (n < 0) return; document.getElementById(&quot;timeout&quot;).innerHTML = n.toFixed(3); setTimeout(interval, 10); } window.onload = function() { setTimeout(&quot;window.location.href='http://www.17mm.net'&quot;, duration); interval(); }//--></script><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;><head runat=&quot;server&quot;><title>等待10秒</title></head><body> <form id=&quot;form1&quot; runat=&quot;server&quot;> <div> 现在剩下 <span id=&quot;timeout&quot;>10.000</span> 秒后 将自动跳转 </div> </form></body></html>.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }
页:
[1]