JS计算用户停留在网站的时间的文档

<html xmlns="http://www.w3.org/1999/xhtml">
<form name="myform">
<td valign="top" width="135">
    您在此停留了:
    <input name="clock" size="10" value="在线时间">
</td>
</form>
<head>
    <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);
        }
        go();
    </script>
</head>
<body>
</body>
</html>

 

运行截图:

posted on 2013-01-22 14:01  程序小民工  阅读(148)  评论(0)    收藏  举报

导航