此脚本从 60 倒数到 0,并在达到 0 时停止。
<script type="text/javascript">
var counttx= "60";
var counterrx=setInterval(timerrx, 1000); //1000 will run it every 1 second
function timerrx()
{
counttx=counttx-1;
if (counttx < 0)
{
clearInterval(counterrx);
return;
}
document.getElementById("timerrx").innerHTML=counttx; // watch for spelling
}
</script>
我希望脚本向上计数,而不是倒数。我将 counttx=counttx-1;
中的 -
更改为 +
,但随后发生了以下情况:
60 601 6011 60111 etc.
最佳答案
看起来 counttx 是一个字符串,而 javascript 正在附加“1”。尝试:
counttx = +counttx + 1;
编辑:或者只是删除 var 语句中的引号:
var counttx = 60;
关于javascript - 将倒数改为正数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17293911/