基于原生JS的电子时钟

电子时钟


function toDate(n){
        if(n<10){
            return '0'+n;
        }else{
            return ''+n;
        }
    };
    window.onload = function(){
        function trick(){
            var oDate = new Date();
            var H = toDate(oDate.getHours());
            var M = toDate(oDate.getMinutes());
            var S = toDate(oDate.getSeconds());
            var t = H +":"+ M +":"+S;
            document.getElementById('p1').innerHTML = t;
        }
        setInterval(trick,1000);
    };

你可能感兴趣的:(JS)