<!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 type="text/JavaScript">  var stingTime;
 var   timeLeft   =   60   *   60   *   1000;   
  function   countTime()   
  {   
   document.getElementById("hehe").disabled=true;  if(timeLeft   ==   0)   
  {   
          alert("时间到!");   
          return;   
  }   
          var   startMinutes   =   parseInt(timeLeft   /   (60   *   1000),   10);   
          var   startSec   =   parseInt((timeLeft   -   startMinutes   *   60   *   1000)/1000)   
          document.getElementById("timeDiv").innerHTML   =   "剩余时间:"   +   startMinutes   +   "分钟"   +   startSec   +   "秒";   
          timeLeft   =   timeLeft   -   1000;   
          setTimeout('countTime()',1000);   
  }   </script> </head> 
<body> 
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div>
 </body> </html>

解决方案 »

  1.   

    <FORM name=myform>剩余时间: <INPUT class=text2 size=10 value=剩余时间 
          name=clock> <INPUT type=hidden size=50 name=times>  
    <% 
    Session("tryTime")="2008/9/9 09:50:00" '这里必须是设定的一个时间,你可以是在登陆的时候设置
    TimeGet=Session("tryTime")''这是ASP控制的时间 
    %> 
    <SCRIPT language=JavaScript> 
    var id, iM = 0, iS = 1; 
    var start1 ="<%=TimeGet%>"; 
    var start=new Date(start1) 
    if (document.myform.times.value==""){ 
    starts=start.getTime(); 
    }else{ 
    starts=document.myform.times.value; 

    //document.myform.clock.value=start.getSeconds(); 
    function go() 

    now = new Date(); 
    time = (2700000-(now.getTime()-starts))/1000; 
    //time = (10000-(now.getTime()-starts))/1000; 
    time = Math.floor( time); 
    iS = time % 60; 
    iM = Math.floor( time / 60); if ( iS < 10){ 
    document.myform.clock.value = " " + iM + ":0" + iS; 
    }else{ 
    document.myform.clock.value = " " + iM + ":" + iS; 

    document.myform.times.value =starts; 
    if (time==300){ 
    alert("请抓紧时间答题,距交卷还有5分钟。"); 

    if (time==0){ 
    alert("时间到,请交卷。"); 
    window.location="test.asp?gopage=jiaojuan&choose=" + document.form1.choose.value; 

    id = setTimeout( "go()", 1000); } 
    go(); 
          </SCRIPT> 
    </form> 
      

  2.   


    <HTML>   
    <HEAD>   
    <TITLE></TITLE>   
    </HEAD>   
    <BODY>   
    <form name=myform><input type=text name=random value=""   
      style="background-color: #ccffff; border: 1px solid #d3d3d3; font-size: 50pt;; height: 70px; width: 75px;">   
    <input type=button value="begin" onclick=begin() name=button1> <input   
      type=button value="end" onclick=end() name=button2></form>   
    </BODY>   
    <script language=javascript>   
        var flg    
        function begin() {    
            flg = 1   
            nothing()    
        }    
        function end() {    
            flg = 0   
        }    
        function nothing() {    
            var x = 51   
            while (x > 50) {    
                x = Math.random()    
                x = Math.floor(x * 100 / 2) + 1    
            }    
            document.myform.random.value = x   
            if (flg == 0)    
                return false    
            setTimeout("nothing()", 40)    
        }    
    </script>   
    </HTML>  
      

  3.   


    <!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 type="text/JavaScript">  var stingTime;
     var   timeLeft   =   60   *   60   *   1000;   
      function   countTime()   
      {   
    document.getElementById("hehe").disabled=true;
    document.getElementById("hehe").value="交卷";
      if(timeLeft   ==   0)   
      {   
      alert("时间到!");   
      return;   
      }
      if(timeLeft <=45 *60*1000)
      {
    document.getElementById("hehe").disabled=false;
      }
              var   startMinutes   =   parseInt(timeLeft   /   (60   *   1000),   10);   
              var   startSec   =   parseInt((timeLeft   -   startMinutes   *   60   *   1000)/1000)   
              document.getElementById("timeDiv").innerHTML   =   "剩余时间:"   +   startMinutes   +   "分钟"   +   startSec   +   "秒";   
              timeLeft   =   timeLeft   -   1000;   
              setTimeout('countTime()',1000);   
      }   </script> </head> 
    <body> 
    <input type='button' value='开始考试' onclick='countTime();' id='hehe'>
    <div id='timeDiv'></div>
     </body> </html>
      

  4.   

    F5是禁用不掉的,及时不用F5也可以实现页面的初始化,要达到数据的一致性,必须保存session 或者coockie来实现!!!!
      

  5.   

    <SCRIPT LANGUAGE="JavaScript">   
    var maxtime = 24*60*60 //24天,按秒计算,自己调整!   
    function CountDown(){   
    if(maxtime>=0){  
    day=Math.floor(maxtime/3600);
    minutes = Math.floor(maxtime/1440);   
    seconds = Math.floor(maxtime%60);   
    msg = "距离考试还有"+day+"天"+minutes+"分"+seconds+"秒";   
    document.all["timer"].innerHTML=msg;   
    if(maxtime == 5*60) alert('注意,还有5分钟!');   
    --maxtime;   
    }   
    else{   
    clearInterval(timer);   
    alert("时间到,结束!");   
    }   
    }   
    timer = setInterval("CountDown()",1000); 
    </SCRIPT>   
    <div id="timer" style="color:red"></div> 
    =========以上的都是在不刷新页面的前提下完成的。如果想刷新后也可以,可以通过 Cookie来实现
    具体Cookie操作见:http://topic.csdn.net/u/20090424/15/407d498a-7286-46d4-92d7-fab1cf54c5ef.html
    5楼我的回复,Cookie基本操作
      

  6.   

    是的可以使用JavaScript来读取cookie保存的时间和当前时间比较来实现倒计时。
      

  7.   

    真是爱死你们了,真想每个人都给分呢MUA!