js笔记(5)--location的用法

!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
</style>
<script>
    setInterval("goto_baidu()",1000);//刚开始需要停止一秒才执行函数,一秒执行一次函数
    var t=5;//定义时间t等于5秒;
  function goto_baidu() {
      if(t==0){
        location.href="http://www.baidu.com" ;
      }
 document.getElementById("show").innerHTML=t;
t--;//执行一次时间减一
}
</script>
<body>
  <!-- 为了解决上秒计时器的bug,上面定义t为5秒,但是setInterval("goto_baidu()",1000)要等待一秒才执行,所以设置这里标签为6,使网页更加连贯 -->
    <label>还有</label><span id="show">6</span><label>秒,跳转到百度!</label>

</body>
</html>

 

posted @ 2019-11-26 19:38  兜里还剩五块出头  阅读(183)  评论(0)    收藏  举报