我有一个moneycounter,显示每个人在每个decisec赚的钱。它工作正常,但当我切换到另一个选项卡或最小化网页时,计数停止。当我回到页面时,计数器才会恢复。我还没有找到类似的话题,有人知道如何解决这个问题吗?
<script>
window.onload = function(){
document.getElementById("maandmoney").value = 2000;
}
var money=0;
var r;
var moneypdsec;
var timer=setInterval(function(){moneyTimer()},100);
function moneyTimer() {
r = document.getElementById("maandmoney").value;
moneypdsec = r / 26297438.3;//months to decisec
money += moneypdsec;
document.getElementById("counter").innerHTML = money.toFixed(4);
}
function salaris() {
money = 0;
r = document.getElementById("maandmoney").value;
}
</script>
<textarea id="maandmoney"></textarea>
<div id="reset"><a href="" onClick="salaris();return false;">R</a> </div>
<p id="counter">0</p>