我希望用户每次在输入运行重置倒计时后键入,我添加clearTimeout
但它不起作用。我该怎么办?(请在我的代码中帮助我,我不想要新代码。)
演示:http: //jsfiddle.net/qySNq/
html:
<input id="MizMah">
<div id="Seconds" style="font-size: 80px;">5</div>
js代码:
$('#MizMah').live('keyup', function () {
function render(n) {
var digits = [],
r;
do {
r = n % 10;
n = (n - r) / 10;
digits.unshift([r].join(''));
} while (n > 0);
$('#Seconds').html(digits.join(''));
}
(function timer(current) {
render(current);
if (current > 0) {
myTimeout = setTimeout(function () {
timer(current - 1);
}, 1100);
clearTimeout(myTimeout);
}
}(5));
})