<body onload="countTimeFunction()">

解决方案 »

  1.   

    <body onload="go()" onbeforeunload="alert('你一共呆了'+document.myform.clock.value )">
    <form name="myform">
    <input name="clock">
    </form>
    <script language="JavaScript">
    var id, iM = 0, iS = 1;
    start = new Date();
    function go()
    {
    now = new Date();
    time = (now.getTime() - start.getTime()) / 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 + " 秒";
    id = setTimeout( "go()", 1000);
    }
    </script>
      

  2.   

    每一分钟发一个xmlhttp到服务器端计数咯,顺便取回累计数值显示在页面或者状态栏也成。