这是我们当前的代码:
$('#click').click(function(e){
var country = $("#country").val();
$this = $("#conv");
$this.css({"text-align":"center","font-size":"18px"});
$this.html("<div style='margin-top: -4px;'>We're sorry but this website is not available in your country <strong>(" + country + ")</strong><br /><br /><a href='http://www.site.com/'>Please click here to visit our partner website!</a></div>")
});
基本上,我们希望 HTML 能够显示:
Please click here to visit our partner website or you'll be automatically redirected in 5 seconds!
我们希望 5 秒倒计时,因此它将显示 5、4、3、2、1,然后重定向到网站。
如何进行计数器并重定向用户?我猜 setTimeout()
旁边有一个计数变量和 $count--
以及一个窗口位置 href?
谢谢
最佳答案
类似这样的事情:
<span id="counter"></span>
JS:
var count = 5;
var counter = document.getElementById('counter');
setInterval(function(){
count--;
counter.innerHTML = count;
if (count === 0) {
window.location = 'http://www.yourwebsite.com';
}
}, 1000);
关于javascript - 重定向和倒计时,jquery onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7845548/