阅读 12

js 30分钟倒计时

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div id="countdown">还剩 30 分 00 秒</div>
        <script>    
            window.onload=function(){
                var countdown=document.getElementById("countdown");

                var time=1800;//30分钟换算成1800秒

                setInterval(function(){
                    time=time-1;
                    var minute=parseInt(time/60);
                    var second=parseInt(time%60);
                        countdown.innerHTML='还剩'+minute+'分'+second+'秒';
                },1000);
            }

        </script>

    </body>
</html>

<p id="time1"></p>
<p id="time2"></p>
<p id="time3"></p>
<p id="time4"></p>

var outTime = function (time, id){
	var countdown= document.getElementById(id);

	setInterval(function(){
		time= time - 1;
	   var minute= parseInt(time/60);
	   var second= parseInt(time%60);
		   countdown.innerHTML= "剩余00:00:" + minute+':'+second;
	},1000);
}

outTime(1800, "time1")
outTime(1200, "time2")
outTime(1700, "time3")
outTime(1650, "time4")
复制代码