js实现10秒倒计时跳转,一般用setTimeout或者setInterval,还有其它的函数来实现吗
function showTime(count) {
document.getElementById('showtimes').innerHTML = count;
if (count == 0) {
// do job
} else {
count -= 1;
setTimeout(function () {
showTime(count);
}, 1000);
}
}
顺手吐个槽<meta http-equiv="refresh" content="10; url=http://.com" />
<script type="text/javascript">
//设定倒数秒数
var t = 10;
//显示倒数秒数
function showTime(){
t -= 1;
document.getElementById('showtimes').innerHTML= t;
if(t==0){
location.href='error404.asp';
}
//每秒执行一次,showTime()
setTimeout("showTime()",1000);
}
//执行showTime()
showTime();
</script>
一般这样写就行了。