function show_date_time() {
s.innerText = s.innerText - 1;
if (s.innerText < 0) {
if (m.innerText >= 1)
{
if (m.innerText <= 9)
{   
m.innerText = "0" + m.innerText-1; 

else

m.innerText = m.innerText - 1; 
}
s.innerText = 59; 
}
else {
s.innerText = "00";
}
}
else if (s.innerText <= 9) {
s.innerText = "0" + s.innerText
}
if (m.innerText <= 0) {
if (h.innerText >= 1) {if (h.innerText <= 9) {
h.innerText = "0" + h.innerText - 1;
}
else {
h.innerText = h.innerText - 1;
}
m.innerText = 59;
}
else {
m.innerText = "00";
}
}
else if(m.innerText<=9)
{
m.innerText="0"+m.innerText;
}
if (h.innerText <= 0) {
h.innerText = "00";
}
if (h.innerText <= 0 && m.innerText <= 0 && s.innerText <= 0) {
GetTime ();
start =0;
return;
}
}
var h;
var m;
var s; 
 
很怪得事情,在IE八下面,做了一个js倒计时,当用户离开这个页面,然后新打开一个选项卡的时候,这个倒计时,就走得很慢.例如:我打开这个js倒计的页面了,然后又新建了一个选项卡,去看别的页面了,过一分钟后,再看js倒计时得这个页面,时间是几乎没有走着得

解决方案 »

  1.   

    document.writeln("<!--done-->");
            document.writeln("<div class=\"newsItem\">");
            document.writeln(" <b><align=center><font color=red size=4>谷百优大赛结束倒计时<\/b><\/font> ");
            document.writeln("");
            document.writeln("<span id=\"span_dt_dt\" style=\'align=center no:1px solid black;background-color:#FFFFFF\' ><\/span> ");
            document.writeln("");
            document.writeln("<SCRIPT language=javascript> ");
            document.writeln("<!-- ");
            document.writeln("\/\/document.write(\"\"); ");
            document.writeln("");
            document.writeln("function show_date_time(){ ");
            document.writeln("window.setTimeout(\"show_date_time()\", 1000); ");
            document.writeln("BirthDay=new Date(\"6-1-2009\");\/\/这个日期是可以修改的 ");
            document.writeln("today=new Date(); ");
            document.writeln("timeold=(BirthDay.getTime()-today.getTime()); ");
            document.writeln("sectimeold=timeold\/1000 ");
            document.writeln("secondsold=Math.floor(sectimeold); ");
            document.writeln("msPerDay=24*60*60*1000 ");
            document.writeln("e_daysold=timeold\/msPerDay ");
            document.writeln("daysold=Math.floor(e_daysold); ");
            document.writeln("e_hrsold=(e_daysold-daysold)*24; ");
            document.writeln("hrsold=Math.floor(e_hrsold); ");
            document.writeln("e_minsold=(e_hrsold-hrsold)*60; ");
            document.writeln("minsold=Math.floor((e_hrsold-hrsold)*60); ");
            document.writeln("seconds=Math.floor((e_minsold-minsold)*60); ");
            document.writeln("span_dt_dt.innerHTML=\"<b><align=center><font color=00CC00 size=4>\"+daysold+\"天\"+hrsold+\"小时\"+minsold+\"分\"+seconds+\"秒\"+\"<\/b><br><\/font>\" ; ");
            document.writeln("");
            document.writeln("} ");
            document.writeln("");
            document.writeln("show_date_time(); ");
            document.writeln("");
            document.writeln("\/\/--> ");
            document.writeln("<\/SCRIPT>");
      

  2.   

    <script type="text/javascript">
    var c=100
    var t
    function timedCount()
     {
     document.getElementById('txt').value=c;
     c=c-1;
     if(c==0){要干吗?}
     t=setTimeout("timedCount()",1000);
     }
    </script>
    不知道楼主的倒计时是不是这个意思?