如何多个这个javascript倒计时器?

时间:2016-05-23 09:50:48

标签: javascript jquery countdowntimer

我必须在我的链接网站添加倒数计时器。我应该怎么做多个计时器?需要多个localstorage初始化或cookie。我必须在我的链接网站上添加一个倒数计时器。我应该怎么做多个计时器?需要多个localstorage初始化或cookie。 jsfiddle

(function() {
    function gT_XXX(oE_XXX) {
        var arr = oE_XXX.innerHTML.split(':')
        return 1000 * (3600 * (+arr[0]) + 60 * (+arr[1]) + (+arr[2]));
    }

    function two_dig_XXX(t) {
        return (parseInt(t) / 100).toFixed(2).toString().split('.')[1];
    }

    function getHH_MM_SS_XXX(sek) {
        return '<b class="timerok">' + two_dig_XXX(sek / 3600) + ':' + two_dig_XXX((sek / 60) % 60) + ':' + two_dig_XXX(sek % 60) + '</b>';
    }
    var tId_XXX;
    var fV_XXX;
    var eD_XXX = localStorage.eD_XXX;
    sT_XXX = function(sel_XXX, test_XXX) {
        var oE_XXX = document.getElementById(sel_XXX);
        clearInterval(tId_XXX);
        if (!fV_XXX) fV_XXX = oE_XXX.innerHTML;
        if (test_XXX == 2) {
            delete localStorage.eD_XXX;
            return
        }
        if (test_XXX == 3) {
            oE_XXX.innerHTML = fV_XXX;
            delete localStorage.eD_XXX;
            return
        }
        if (!eD_XXX && !test_XXX) return false;
        var deltaT_XXX = gT_XXX(oE_XXX);
        if (test_XXX) {
            oE_XXX.innerHTML = fV_XXX;
            deltaT_XXX = gT_XXX(oE_XXX);
            delete localStorage.eD_XXX;
            eD_XXX = localStorage.eD_XXX;
        }
        var thisTime_XXX = +new Date();
        if (!eD_XXX) {
            var timeEnd_XXX = thisTime_XXX + deltaT_XXX;
            localStorage.eD_XXX = sel_XXX + ',' + timeEnd_XXX;
        }
        if (eD_XXX && !test_XXX) {
            var arr = eD_XXX.split(',');
            var oE_XXX = document.getElementById(arr[0]);
            var timeEnd_XXX = +arr[1];
        }

        function setOutTime_XXX() {
            if (+new Date() >= timeEnd_XXX) {
                clearInterval(tId_XXX);
                oE_XXX.innerHTML = 'END';
                $("#XXX").animate({
                    backgroundColor: "#FBFDA7",
                }, 1500);
                delete localStorage.eD_XXX;
                return;
            }
            var tF_XXX = parseInt((timeEnd_XXX - +new Date()) / 1000);
            oE_XXX.innerHTML = getHH_MM_SS_XXX(tF_XXX);
        }
        setOutTime_XXX();
        tId_XXX = setInterval(setOutTime_XXX, 1000);
    }
    sT_XXX("mt_XXX", 0);
    window.onfocus = function() {
        sT_XXX("mt_XXX", 0);
    }
}());
<span class="timerx">
<span id="mt_XXX" class="timer_text_num" style="">00:10:00</span>
<input type="button" value="start" class="tbu" onclick="sT_XXX('mt_XXX',1);">
<input type="button" value="reset" class="tbu" onclick="sT_XXX('mt_XXX',3)">
</span><br>
<span class="timerx">
<span id="mt_XXX" class="timer_text_num" style="">00:20:00</span>
<input type="button" value="start" class="tbu" onclick="sT_XXX('mt_XXX',1);">
<input type="button" value="reset" class="tbu" onclick="sT_XXX('mt_XXX',3)">
</span>

0 个答案:

没有答案