基于原生JS的定时器

定时器

::

//定时器
    var s = "00";
    var m = '00';
    var h = '00';
    var i = 0;
    var k = 0;
    document.getElementById('h1').innerText = h;
    document.getElementById('m1').innerText = m;
    document.getElementById('s1').innerText = s;
    var btn3 = document.getElementById('btn1');
    btn3.onclick = function(){
        var j = 0;
        readytrick = setInterval(function(){
           j++;
           if(j<60){
               document.getElementById('s1').innerText  = toDate(j);
           }else{
               j = 0;
               readytrick;
               minutes();
           }
       },1000)
    };
    function minutes(){
        i++;
        if(i<60){
            document.getElementById('m1').innerText = toDate(i);
        }else{
            hours();
            i = 0;
        }
    }
    function hours(){
        k++;
        if(k<12){
            document.getElementById('h1').innerText = toDate(k);
        }else{
            k= 0;
        }
    }
    var btn4 = document.getElementById('btn2');
    btn4.onclick = function(){
        clearInterval(readytrick);
    }


你可能感兴趣的:(JS)