js控制n秒后跳转到指定页面,并显示倒计时
发布时间:2018-07-11 22:25:58编辑:丝画阁阅读(761)
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>setTimeout</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div id='div1'>
-
</div>
-
</form>
-
</body>
-
</html>
-
-
-
<script type="text/javascript">
-
//设定倒数秒数
-
var t = 10;
-
//显示倒数秒数
-
function showTime(){
-
t -= 1;
-
document.getElementById('div1').innerHTML= t;
-
if(t==0){
-
location.href='http://www.baidu.com';
-
}
-
//每秒执行一次,showTime()
-
setTimeout("showTime()",1000);
-
}
-
-
-
//执行showTime()
-
showTime();
-
</script>