JavaScript使用setInterval实现倒计时操作
效果图:
时间可以自己设置
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="一分钟倒计时" onclick="daojishi()" />
<label id="time">60</label>
<script>
function daojishi () {
var time = 60;
var interval = setInterval(function () {
document.getElementById("time").innerHTML=time;
time-=1;
if(time==-1){
clearInterval(interval)
document.getElementById("time").innerHTML="倒计时结束"
}
},1000)
}
</script>
</body>
</html>