2013-12-18 103 views
-3

我需要一些幫助,增加值/ 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; 
} 

這是可怕的錯誤! 問題!

當我點擊圖像。

函數啓動。

該函數每秒鐘將「數字」的值增加1。

感謝

+3

這不是PHP ... – naththedeveloper

回答

0

如果你真的想要增加值完全在1秒鐘後,我建議你保存的開始時間(Unix時間戳記例如秒自1/1/1970)。如果你想知道你增加的變量的價值只是從開始價值減去。

因爲你提到的PHP和向我們展示JS代碼我把它的僞代碼

function getUnixTimeStampNow() { 
    return Math.round((new Date()).getTime()/1000); 
} 

var start = getUnixTimeStampNow(); 

// at any time do 

var current_value = getUnixTimeStampNow() - start;