2 回答
![?](http://img1.sycdn.imooc.com/54584cde0001d19202200220-100-100.jpg)
TA贡献1873条经验 获得超9个赞
我不明白你到底想要什么帮助,但我根据我的理解修复了它
var counter = 0;
var counterSchedule;
var input = document.getElementById("number");
var counterSpan = document.getElementById("counter");
function startCounterAnimation() {
counterSchedule = setInterval(showCounter, 1000);
}
function showCounter() {
if (~~input.value) {
if (counter >= 10)
counter = 0;
counter++;
counterSpan.innerHTML = input.value + " X " + counter + " = " + eval(input.value + " * " + counter);
}
}
function stopCounterAnimation() {
clearInterval(counterSchedule);
input.value = "";
counter = 0;
}
<input onClick="stopCounterAnimation()" id="number" type="text">
<button onclick="startCounterAnimation()">Start Animation</button>
<button onclick="stopCounterAnimation()">Stop Animation</button>
<br/><br/>
<span id="counter"></span>
![?](http://img1.sycdn.imooc.com/54584cde0001d19202200220-100-100.jpg)
TA贡献1811条经验 获得超5个赞
我不确定我是否正确理解了您的问题(我真的没有看到问题)。您的代码看起来不错,但您希望它在达到 10 后重新开始?尝试使用模运算符 % 所以替换
counterSpan.innerHTML = counter;
和
counterSpan.innerHTML = counter % 10;
告诉我我是否误解了这个问题。
添加回答
举报