怎么会是0,我这里是打个比方写了个alert,如果事件很复杂,计时的时间也就很长了,

解决方案 »

  1.   

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE></TITLE>
    </HEAD>
    <BODY><INPUT type="text" id=text1 name=text1 onclick="a()"></BODY>
    </HTML>
    <SCRIPT LANGUAGE=javascript>
    <!--
    var timer = 0;
    var clock = 0;
    function a(){
      timer = window.setTimeout(chageTime,10);
      window.setTimeout(function (){timer = null},7000);
    }function chageTime(){
       if (timer != null){
          timer = window.setTimeout(chageTime,1000);
          clock++;
      text1.value = clock;
       }else{
       alert(clock);
       }
    }
    //-->
    </SCRIPT>
      

  2.   

    <html>
    <head>
    <script language="javascript">
       function a()
       {
          d1 = new Date();
      d1 = d1.getTime();
          form1.submit();
      d2 = new Date();
      d2 = d2.getTime();
          alert(((d2-d1)/1000)+"s");
        }
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="" target="_blank">
     <input type="text" name="txt">
    <input type="button" name="button" value="提交" onclick="a()">
    </form>
    </body>
    </html>