function fomat(str){
  if( str.length < 2){
    str = "0" + str;
  }
  return str;
}调用 
span_dt_dt.innerHTML="还剩"+fomat(daysold)+"天"+fomat(hrsold)+"小时"+fomat(minsold)+"分"+fomat(seconds)+"秒"+"!" ; 

解决方案 »

  1.   

    if( str.length < 2){
        str = "0" + str;
      }
      

  2.   

    "80天8小时8分8秒".replace(/(\d{1})/g,"0$1")
      

  3.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>cha0</title>
    </head><body background="whb.jpg" bgcolor="#000000"><p align="right"><FONT style="FONT-SIZE: 20pt; FILTER: shadow(color=#13467F,strength=8); WIDTH: 100%; COLOR: #D5E7F5; LINE-HEIGHT: 160%; FONT-FAMILY: 隶书">
    生日倒计时:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp; <br>
    生日倒计时:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp; <br>
    生日倒计时:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp; <br>
    生日倒计时:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp; <br><SCRIPT language=javascript> 
    function format(str){
      if( str.length < 2){
        str = "0" + str;
      }
      return str;
    }
    </SCRIPT><span id="span_dt_dt" ></span> 
    <SCRIPT language=javascript> 
    <!-- 
    //document.write(""); function show_date_time(){ 
    window.setTimeout("show_date_time()", 1000); 
    BirthDay=new Date("9-30-2008");//这个日期是可以修改的 
    today=new Date(); 
    timeold=(BirthDay.getTime()-today.getTime()); 
    sectimeold=timeold/1000 
    secondsold=Math.floor(sectimeold); 
    msPerDay=24*60*60*1000 
    e_daysold=timeold/msPerDay 
    daysold=Math.floor(e_daysold); 
    e_hrsold=(e_daysold-daysold)*24; 
    hrsold=Math.floor(e_hrsold); 
    e_minsold=(e_hrsold-hrsold)*60; 
    minsold=Math.floor((e_hrsold-hrsold)*60); 
    seconds=Math.floor((e_minsold-minsold)*60); span_dt_dt.innerHTML="还剩"+daysold+"天"+format(hrsold)+"小时"+format(minsold)+"分"+format(seconds)+"秒"+"!" ; } show_date_time(); //--> 
    </SCRIPT> </FONT></td>
    </p>
    </body></html>还是不行啊,上面是这个html的全部代码,请各位再帮小弟改改。我接触网页编程少。
      

  4.   

    搞定了,format()的参数是字符串类型,要把hrsold等参数转换为字符串,再调用format()就可以了