【问题标题】:Increase value / Script增加值/脚本
【发布时间】:2013-12-18 09:40:47
【问题描述】:

我需要一些帮助来增加值/每秒 1。

我有

<script>
function incrementValue()
{
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = value;
return false;
}
</script>

现在我需要一个函数来增加“数字”的值并开始每秒添加 +1,直到我点击另一个图像。

我唯一能做的是:

function incrementvale()
var incrementTime = 1;
var incrementBy = 1;
private var counter = 0;

function Start () {
InvokeRepeating("Increment", incrementTime, incrementTime);
}

function Increment () {
counter += incrementBy;
}

这是非常错误的! 问题!

当我点击图片时。

函数开始。

该函数每秒将“number”的值增加 1。

谢谢

【问题讨论】:

    标签: javascript timer increment


    【解决方案1】:

    如果你真的想在 1 秒后增加一个值,我建议你保存开始时间(Unix 时间戳,例如自 1970 年 1 月 1 日以来的秒数)。如果您想知道递增变量的值,只需从起始值中减去即可。

    因为您提到了 PHP 并向我们展示了 JS 代码,所以我将其保留在伪代码中

    function getUnixTimeStampNow() {
        return Math.round((new Date()).getTime() / 1000);
    }
    
    var start = getUnixTimeStampNow();
    
    // at any time do
    
    var current_value = getUnixTimeStampNow() - start;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 2014-04-06
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多