我尝试用这样的jQuery重置计数器
$i = 1;
function theTimer(startTime){
var counter = $i++;
var currenTime = parseInt(startTime) + counter;
var tMin = Math.floor( parseInt(currenTime) / 60 );
var tHour = Math.floor( parseInt(currenTime) / 3600 );
(other stuff ...)
}
$('.btn-start-timer').click(function(startTime){
var startTime = 320;
banKTimer = setInterval(function() { theTimer(startTime) }, 1000);
});
$('.btn-stop-timer').click(function(){
stoptheTimer = clearInterval(banKTimer);
});
当我重新启动计时器时,我想重置counter = $ i ++。 我忘记了一些东西,却找不到它!
答案 0 :(得分:0)
$('.btn-stop-timer').click(function(){
stoptheTimer = clearInterval(banKTimer);
$i = 0; // Done here to allow you to get $i value for other purpose just
// after clearing the interval.
});