【问题标题】:Counting up numbers that are not lost on page refresh计算页面刷新时没有丢失的数字
【发布时间】:2015-06-04 12:46:27
【问题描述】:

我需要一个号码,该号码将显示为在网站上注册的人。 nuber 将是应该在不损失价值的情况下计算的数字。例如。它应该从 1 开始并继续,如果我刷新页面,它不应该从 1 重新开始。它应该继续。 类似但不保存的示例:

    var minutesLabel = document.getElementById("minutes");
    var secondsLabel = document.getElementById("seconds");
    var totalSeconds = 0;
    setInterval(setTime, 1000);
    function setTime()
    {
        ++totalSeconds;
        secondsLabel.innerHTML = pad(totalSeconds%60);
        minutesLabel.innerHTML = pad(parseInt(totalSeconds/60));
    }

    function pad(val)
    {
        var valString = val + "";
        if(valString.length < 2)
        {
            return "0" + valString;
        }
        else
        {
            return valString;
        }
    }

【问题讨论】:

    标签: javascript jquery arrays timer counter


    【解决方案1】:

    当您刷新页面时,JavaScript 创建的所有内存都会丢失。

    一些选项可能是:

    HTML5 本地存储http://www.w3schools.com/html/html5_webstorage.asp

    Cookieshttp://www.w3schools.com/js/js_cookies.asp

    服务器端数据库,例如 MySQL

    还有服务可以帮助解决这个问题,例如:http://www.webestools.com/pages-views-counter-free-number-pages-views-statistics.html

    【讨论】:

    猜你喜欢
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 2016-01-26
    • 2019-08-07
    • 2020-08-28
    • 2020-09-07
    相关资源
    最近更新 更多