解决方案 »

  1.   

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
    <script type="text/javascript" language="javascript">    var caution = false
        function setCookie(name, value, expires, path, domain, secure) {
            var curCookie = name + "=" + escape(value) +
                    ((expires) ? "; expires=" + expires.toGMTString() : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "")
            if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
            else
                if (confirm("Cookie exceeds 4KB and will be cut!"))
                    document.cookie = curCookie
        }
    function getCookie(name) {
            var prefix = name + "="
            var cookieStartIndex = document.cookie.indexOf(prefix)
            if (cookieStartIndex == -1)
                return null
            var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
            if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
            return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
        }
        function deleteCookie(name, path, domain) {
            if (getCookie(name)) {
                document.cookie = name + "=" +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
            }
        }
        function fixDate(date) {
            var base = new Date(0)
            var skew = base.getTime()
            if (skew > 0)
                date.setTime(date.getTime() - skew)
        } 
    var now = new Date()
        fixDate(now)
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
        var visits = getCookie("counter")
        if (!visits)
            visits = 1
        else
            visits = parseInt(visits) + 1
        setCookie("counter", visits, now)
        document.write("您是到访的第" + visits + "位用户!")
    </script>
    </body>
    </html>
      

  2.   

    var visits = Math.floor(new Date().getTime()/500);
    alert(visits);
    我觉得我已经懒出境界了..
      

  3.   


    = =您好 刷新了没有变化啊 一直是1
    他是将访问人数写到cookie中去然后再读取的,本地测试要用ie才行,webkit内核浏览器本地不能写入cookie。
      

  4.   

    var visits = Math.floor(new Date().getTime()/1000)-139924000;
    alert(visits);
      

  5.   


        function setCookie(key, value, days) {
            var d = new Date();
            d.setDate(d.getDate() + days);
            document.cookie = key + '=' + value + ';expries='+d.toGMTString();
        }
        function getCookie(key) {
            var m = new RegExp(key + '=([^&]+)', 'i').exec(document.cookie);
            if (m)  return parseInt(m[1]); 
            return 10000;//没有存储过cookie返回默认起始值
        }
        var v = getCookie('visited');
        v += parseInt(Math.random() * 20 + 10); //随机增加人数,10~20之间
        setCookie('visited', v, 365);
        document.write("您是到访的第" + v + "位用户!")
      

  6.   

    少打了个0
    var visits = Math.floor(new Date().getTime()/1000)-1399240000;
    alert(visits);