<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
#box{
display:inline-block;}
#box1{
display:inline-block;}
</style>
</head>
<body>
<div id="box">3</div><span>分钟</span>
<div id="box1">0</div><span>秒钟</span>
</body>
<script>
var obox = document.getElementById("box");
var obox1 = document.getElementById("box1");
var t = setInterval (function(){
obox1.innerHTML--;
if(obox.innerHTML == 0 && obox1.innerHTML == 0){
clearInterval(t)
// 条件清除计时器一定要放到自减这一步
}
if(obox1.innerHTML<0){
obox.innerHTML--;
obox1.innerHTML = 59;
}
},1000)
</script>
</html>
JS实现倒计时功能,如3分钟倒计时
猜你喜欢
转载自blog.csdn.net/qq_26705343/article/details/113263213
今日推荐
周排行