<div id="test">5</div>
<script type="text/javascript">
var i = 4
var t = setInterval(function(){
if (i == 0) {
clearInterval(t)
return
}
document.getElementById("test").innerHTML = i
i--
}, 1000)
</script>
望采纳
let n = 0let flag = true
while (n <= 10 || n >= 0) {
if (flag) {
sleep(1000)// 延时函数,单位ms
n++
console.log(n)
} else {
sleep(1000)// 延时函数,单位ms
n--
console.log(n)
}
if (n == 10 || n == 0) {
flag = !flag
}
}