我正在尝试构建像http://codepen.io/GeoffStorbeck/full/RPbGxZ/这样的番茄钟.秒值随机变为NaN,然后在"break"开始后恢复正常.
$('#circle a').click(function() { var timer = $('.time > span').html(); timer = timer.split(':'); var minutes = timer[0]; //Value of minutes var seconds = timer[1]; //Value of seconds var settimer = setInterval(function() { seconds -= 1; console.log(seconds); if (seconds < 0 && minutes != 0) { minutes -= 1; minutes = String(minutes); seconds = 59; } else if (seconds < 10 && seconds.length != 2) seconds = '0' + seconds; if (minutes < 10 && minutes.length < 2) minutes = '0' + minutes; $('.time > span').html(minutes + ':' + seconds); //Start break when session is completed if (minutes == 0 && seconds == 0) { $('.upper').find('h1').text('BREAK'); var time = $('#break').find('span').text(); $('.time > span').html('0' + time + ':00'); $('#circle a').trigger("click"); //Start timer for break } }, 1000); });
这是codepen的链接 http://codepen.io/ibrahimjarif/pen/wMKJWN
我如何解决NaN问题?有没有更好的方法来实现这个?