我想依靠我的网站从3到1(3,2,1,< redirect>),就像在sh.st或adf.ly上一样。我是JavaScript的新手,有人可以帮助我吗?
答案 0 :(得分:2)
这是创建倒计时的快速而肮脏的方式
//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