日期:2014-05-16  浏览次数:20287 次

js倒计时,时分秒
    var examTimeId;
    function tick() {
        examTimeId = setTimeout("tick()", 1000);
        var time = strToTime($("#timer").text());
        if (time > 0)
            time--;
        else {
            clearTimeout(examTimeId);
            alert("时间已到,即将交卷");
            //end();
        }
        $("#timer").text(timeToStr(time));
    };
    function strToTime(str,s){
        var s = s || ":", parts = str.split(s).reverse();
        return parseFloat(parts[0]) + parseFloat(parts[1]) * 60 + parseFloat( parts[2]) * 3600;
    }
    function timeToStr(time,s) {
        var s = s || ":", comple = function (number) {
            number = parseInt(number);
            return number < 10 ? "0" + number : number;
        };
        return comple(time / 3600) + s + comple(time % 3600 / 60) + s + comple(time % 3600 % 60);
    }
    tick();
?

?