<html> <head> <meta charset="UTF-8"> <title>1分钟倒计时</title> <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> </head> <body> <div id="livetime" style="color: black;"></div> </body> <script type="text/javascript"> var timestart = 60;//时间; var timestep = -1; var timeID; function timecount() { $("#livetime").html(formatSeconds(timestart)); timestart += timestep; if(timestart < 0){ timestart = 60;//时间;//赋值0 倒计时结束,就变00:00 return false; //倒计时为0时执行xxxx方法 } timeID=setTimeout("timecount()",1000); } formatSeconds = function(timestart) { var theTime = parseInt(timestart);// 需要转换的时间秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 var theTime3 = 0;// 天 if(theTime >= 60) { theTime1 = parseInt(theTime/60); theTime = parseInt(theTime%60); if(theTime1 > 60) { theTime2 = parseInt(theTime1/60); theTime1 = parseInt(theTime1%60); if(theTime2 > 24){ //大于24小时 theTime3 = parseInt(theTime2/24); theTime2 = parseInt(theTime2%24); } } } else { var result = '00:'; if(theTime < 10) { result += '0'+theTime; } else { result += theTime; } return result; } var result = ''; if(theTime > 0){ // 秒 theTime = parseInt(theTime); if(theTime < 10) { theTime = '0'+theTime; } result = ""+theTime; } else { result += "00"; } if(theTime1 > 0) { // 分钟 theTime1 = parseInt(theTime1); if(theTime1 < 10) { theTime1 = '0'+theTime1; } result = ""+theTime1+":"+result; } else { result += "00"; } if(theTime2 > 0) { // 小时 theTime2 = parseInt(theTime2); if(theTime2 < 10) { theTime2 = '0'+theTime2; } result = ""+theTime2+":"+result; } if(theTime3 > 0) { // 天 theTime3 = parseInt(theTime3); result = ""+theTime3+" "+result; } return result; } timecount(); //倒计时 </script> </html>