首页 > 代码库 > 5秒跳转

5秒跳转

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<script type="text/javascript" language="javascript">
 var count = 4;//读秒
 function showSecond(){
  //innerText设置标签中的文本
  document.getElementById("mySpan").innerText = count;
  count--;
  if(count==0){
   //设置浏览器的url
   window.location.href = "http://www.baidu.com";
  }
 }
 window.setInterval("showSecond()",1000);
</script>
</head>

<body>
<span id="mySpan">5</span>秒后自动跳到百度首页.<a href="http://www.baidu.com">点击进入百度</a>
</body>
</html>