开发者

My clock never makes it past 8 seconds

So, I'm making a simple clock that just counts time from a static starting point. The problem is, when the second mark hits 8, it resets to 0. I can't figure out why. Help!

Here's the clock: http://jsfiddle.net/Ender/jMbem/

Here's the code for it:

HTML:

<h1>Mark's Busted Computer Clock</h1>
<div id="time">
    <span id="hour">146</span>:<span id="minute">45</span>:<span id="second">00</span>
</div>

JS:

$(function() {
    setInterval(UpdateSecond, 1000);
});

function UpdateSecond() {
    var num = parseInt($('#second').text());
    num++;
    if (num == 60) {
        num = 0;
        UpdateMinute();
    }
    if (num < 10) {
        num = "0" + num;
    }
    $('#second').text(num);
}

function UpdateMinute() {
    var num = parseInt($('#minute').text());
    num++;
    if (num == 60) {
        num = 0;
    开发者_高级运维    UpdateHour();
    }
    if (num < 10) {
        num = "0" + num;
    }
    $('#minute').text(num);
}

function UpdateHour() {
    $('#hour').text(parseInt($('#hour').text()) + 1);
}


The problem is that you aren't passing a radix to the parseInt function. Try:

var num = parseInt($('#minute').text(), 10);

More info here: http://www.w3schools.com/jsref/jsref_parseint.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜