WEB 倒計時

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    Response.Write("你已經交卷。");
    //代碼進行處理,跳轉到
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <script type="text/javascript">
    var overDate = 0.004 //設置要倒計時的小時數
    EndTimeMsg = overDate * 60 * 60
    function show() {
      h = Math.floor(EndTimeMsg / 60 / 60);
      m = Math.floor((EndTimeMsg - h * 60 * 60) / 60)
      s = Math.floor((EndTimeMsg - h * 60 * 60 - m * 60))
      document.getElementById("HH").innerHTML = h
      document.getElementById("MM").innerHTML = m
      document.getElementById("SS").innerHTML = s
      EndTimeMsg--;
      if (EndTimeMsg <= 10 && EndTimeMsg > 9) {
        alert(s + " 後將自動交卷");
        document.getElementById("SS").innerHTML = s
        document.getElementById("OK").innerHTML = " 後將自動交卷"
      }
      if (EndTimeMsg < 0) {
        document.getElementById('<%=Button1.ClientID %>').click();
      }
    }
    setInterval("show()", 1000)
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div><strong id="HH"></strong>時 <strong id="MM"></strong>分 <strong id="SS"></strong>
    秒<strong id="OK" style="color: red"></strong> </div>
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="交卷" />
  </form>
</body>
</html>
相關文章
相關標籤/搜索