function min() { document.getElementById('time').innerHTML= "0:" + (--tim > 9 ? tim : '0' + tim); if(!tim) { clearInterval(m); } } var tim =10; var m = setInterval(min, 1000);