日期:2014-05-16 浏览次数:20372 次
<!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>JS实现时分秒倒数</title>
<script language="Javascript" type="text/Javascript">
var h,m,s,hstr,mstr,sstr,timestr;
var etimeMinu = 120; // 总分钟
var etime = etimeMinu * 60;
function timer()
{
??? 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; //1显示01
??? m.toString().length < 2 ? mstr = "0" + m.toString() : mstr = m; //1显示01
??? s.toString().length < 2 ? sstr = "0" + s.toString() : sstr = s; //1显示01
???
??? timestr = hstr + ":" + mstr + ":" + sstr;
??? etime = etime - 1;
?if(etime>0){
??? document.getElementById('timeDiv').innerHTML = timestr;??
?? }else{
??? document.getElementById('timeDiv').innerHTML = 'Enter';
?}
}
</script>
?</head>
<body onload="window.setInterval('timer()',1000);">
<div id="timeDiv"></div>
<input type="button" id="txt" name="txt" value="" />
</body>
</html>