javascript倒计时代码通用函数,可同时多个倒计时。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>倒计时</title>
<script>
//倒计时
function timer(divName,etime)
{
 h = Math.floor(etime / 3600);    //时
 m = Math.floor(etime / 60) % 60; //分
 s = Math.floor(etime % 60);      //秒
 h < 0 ? h = 0 : h = h;
 m < 0 ? m = 0 : m = m;
 s < 0 ? s = 0 : s = s;
 h.toString().length < 2 ? hstr = "0" + h.toString() : hstr = h;
 m.toString().length < 2 ? mstr = "0" + m.toString() : mstr = m;
 s.toString().length < 2 ? sstr = "0" + s.toString() : sstr = s;
 timestr = hstr + ":" + mstr + ":" + sstr;
 document.getElementById(divName).innerHTML = timestr;
 if(etime>0){
  etime = etime - 1;
  window.setTimeout("timer('"+divName+"',"+etime+")",1000);
 }
}

function timeOver(sTime,divName,funName){
 if(sTime>0){
  timer(divName,sTime);
  window.setTimeout(""+funName+"",(sTime+1)*1000);
 }
 else window.setTimeout(""+funName+"",0);
}

function ccc(){
 document.getElementById("ccc").innerHTML ="ccccccc";
}

function ddd(){
 document.getElementById("ddd").innerHTML = "ddddddd";
}
</script>
</head>

<body onload="timeOver(10,'aaa','ccc()');timeOver(15,'bbb','ddd()');">
<div id="aaa">00:00:00</div>
<div id="bbb"></div>
<div id="ccc"></div>
<div id="ddd"></div>
</body>
</html>