【发布时间】:2013-12-10 13:34:27
【问题描述】:
我整天都在寻找解决这个问题的方法。我喜欢在 StackOverflow 上找到的 this Counter,但由于我没有使用 JavaScript 的经验,我不完全确定如何阻止它。
我想出了如何设置值以及何时开始计数等,但现在我想添加一个最大值。 IE:如果计数器达到2000万,则停止。
我尝试了以下方法,但它不起作用:
var simplicity = formatMoney(20000000);
if (amount.innerText <= simplicity){
function update() {
var current = (new Date().getTime() - start)/1000*0.36+0;
amount.innerText = formatMoney(current);
}
setInterval(update,1000);
}
else{
amount.innerText = simplicity;
}
【问题讨论】:
-
你只是在循环之前检查你的 innerHTML 是否简单。我认为您需要将该检查移到您的
update函数中。
标签: javascript