js简易倒计时,好用。3分钟倒计时

js简易倒计时,好用。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<div> <span id="m"></span><span id="s"></span></div>

<script>
var m = 1;  //设置
var s = 5;    //设置
function showtime(){
    document.getElementById('m').innerHTML = m;
    document.getElementById('s').innerHTML = s;
    s = s-1;
    if(s==0){
        m = m -1;
        s = 60
    }
    if(m==0){
       // window.location='http://www.ewceo.com';//倒计时结束跳转到www.ewceo.com
    }
      
    if(m<0 && s==60){   //当时间为0分1秒时,暂停
        clearInterval(settime);
        
    }
    
}
clearInterval(settime);
var settime = setInterval(function(){
    showtime();
},1000);
</script>
</body>
</html>

 

posted @ 2015-04-10 09:06  Shimily  阅读(2204)  评论(0编辑  收藏  举报