<html> <head> <meta charset="UTF-8"> <title>6分钟倒计时 & 60秒倒计时</title> <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> </head> <body> <div id="timer" style="color:red"></div> <div id="livetime"></div> </body> <script type="text/javascript"> var oBox= document.getElementById('timer'); var maxtime = 6 * 60; function CountDown() { if (maxtime >= 0) { minutes = Math.floor(maxtime / 60); seconds = Math.floor(maxtime % 60); msg = "距离结束还有" + minutes + "分" + seconds + "秒"; oBox.innerHTML = msg; if (maxtime == 3 * 60)alert("还剩3分钟"); --maxtime; } else{ clearInterval(timer); alert("时间到,结束!"); } } timer = setInterval("CountDown()", 1000); var timestart = 60;//时间; var timestep = -1; var timeID; function timecount() { $("#livetime").html(timestart); timestart += timestep; if(timestart < 0){ $("#confirmPayment").hide(); $("#cancel").show(); return false; //倒计时为0时执行xxxx方法 } timeID=setTimeout("timecount()",1000); } timecount(); //倒计时 </script> </html>