日期:2014-05-16  浏览次数:20437 次

JSP简单倒计时器
<!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=utf-8" />
  <title>倒计时</title>
</head>
<body>
  <input name="times" type="text" id="times" size="4" />
  / 分
  <input name="StartTime" type="button" value="开始计时" onclick=
showTime();;
/>
  <input name="times" type="text" id="timeShow" />
  <input name="times" type="text" id="timeshow" size="8" />
  <input name="StartTime" type="button" value="停止计时" onclick=
stopTime();;
/>

<form action="" method="post" name="form" id="form">
姓名:
<input name="name" type="text" />
<input name="name" type="submit" value="提交" />
</form>



</body>
</html>
<script language="javaScript">
var timesDate = null;
function startTime(pro) {
  var dateTime = new Date();
  var times = --pro;
  document.getElementById("timeShow").value = dateTime.toLocaleString();
  timesDate = window.setTimeout("startTime(" + times + ")", 1000);
  if (times <= 60) {
   if (times < 10) {
    document.getElementById("timeshow").value = "00:00:" + "0" + times;
   } else {
    document.getElementById("timeshow").value = "00:00:" + times;
   }
  } else if (pro > 60 && pro < 3600) {
   var mm = Math.floor(pro / 60);
   if (mm < 10) {
    if ((times - (mm * 60)) < 10) {
     document.getElementById("timeshow").value = "00:0" + mm + ":"
       + "0" + (times - (mm * 60));
    } else {
     document.getElementById("timeshow").value = "00:0" + mm + ":"
       + (times - (mm * 60));
    }
   } else {
    if ((times - (mm * 60)) < 10) {
     document.getElementById("timeshow").value ="00:"+mm + ":" + "0"
       + (times - (mm * 60));
    } else {
     document.getElementById("timeshow").value ="00:"+mm + ":"
       + (times - (mm * 60));
    }
   }
  } else if (pro >= 3600) {
   var hh = Math.floor(pro / 3600);
   var mm = Math.floor((pro - (hh * 3600)) / 60);
   var ss = (pro - ((hh * 3600) + (mm * 60)));
   if (hh < 10) {
    if (mm < 10) {
     if (ss < 10) {
      document.getElementById("timeshow").value = "0" + hh
        + ":" + "0" + mm + ":" + "0" + ss;
     } else {
      document.getElementById("timeshow").value = "0" + hh
        + ":" + "0" + mm + ":" + ss;
     }
    } else {
     document.getElementById("timeshow").value = "0" + hh + ":"
       + mm + ":" + ss;
    }
   } else {
    if (mm < 10) {
     if (ss < 10) {
      document.getElementById("timeshow").value = hh + ":"