【发布时间】:2016-01-27 08:56:31
【问题描述】:
我正在创建一个计数器,但我很难做到。 计数器的目标是每经过一秒,数字就会增加 170。 正如你在下面看到的,这个数字没有加起来,而是在一个新的行上,主要是因为我不知道如何让它加起来。来自The Economist的这个时钟之类的东西@
<!DOCTYPE html>
<html>
<body>
<p>Click the button see how much AirHelps market increases by every second.</p>
<button onclick="counterFunction()">See it now</button>
<p id="counter"></p>
<script>
function counterFunction() {
setTimeout(function () {
var text = "";
var i = 170;
while (i < 3500) {
text += "<br>The number is " + i;
i+=170;
}, 1000) }
document.getElementById("counter").innerHTML = text;
}
</script>
</body>
</html>
关于如何做到这一点以及我的代码有什么问题有什么想法吗?
【问题讨论】:
标签: javascript loops time while-loop