我想从 3 到 1(3, 2, 1,
最佳答案
这是一种创建倒计时的快速但肮脏的方法
//Calls countdown function
var count = 3;
countdown(count);
//counts and redirect
function countdown(timer) {
//Keeps the interval ID for later clear
var intervalID;
intervalID = setInterval(function () {
display(timer);
timer = timer - 1;
if (timer < 0) {
//Clears the timeout
clearTimeout(intervalID);
// You can redirect the user after it
// window.location.assign("YourURL");
}
}, 1000);
}
//Modifies the countdown display
function display(timer) {
//Execute your diplay modification logic
}
您可以查看here
关于JavaScript 计数 1、2、3 并重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32661039/