按钮显示5,4,3,2,1
之后自动跳转下一个界面,弄了半天没搞明白,怎么改变成多个值
setInterval
this.se = 5
this.timer = setInterval(() => {
console.log(this.se)
if (this.se === 0) {
clearInterval(this.timer)
alert(1)
} else {
this.se--
}
}, 1000)
我觉得你在找jquery-step
<!DOCTYPE html>
<html>
<body>
<button type="button" id="b1">5</button>
</body>
<script>
var b1 = document.getElementById("b1");
var num = b1.innerText;
window.setInterval(function() {
num--;
if (num > 0) {
b1.innerText = num;
} else {
window.clearInterval();
window.location.href = "A.html"
}
}, 500);
</script>
</html>