zoukankan      html  css  js  c++  java
  • 用js实现动态显示指定时间的倒计时并倒计时完毕后跳转

     首先看下前端代码: 

       

    <body style="text-align: center;">
            <br/>系统超时或未登录!<br/><br/>
            <span id="spanTime" style="color: red">5</span>
            秒后自动跳转到登录界面,或者<a href='javascript:redirect()'>点击这里</a>直接登录!
      </body>

      然后是js代码:

          

     <script type="text/javascript">
          window.onload = function(){
              //1.首先声明seconds
              var seconds = 4;
              //2.声明定时器
              var timer = null;
              //3.开启定时器
              timer = setInterval(show,1000);
              //4.设置跳转路径

    var location="<%=request.getContextPath() %>/admin/login/index.do";这里改成需要跳转的路径 //开启定时器后要执行的函数 function redirect(){ parent.parent.parent.parent.location.href = location; } function show(){ if(seconds==0){ clearInterval(timer);//清除定时器 parent.parent.parent.parent.location.href = location; return; } //将不断变化的秒数显示在页面上 document.getElementById('spanTime').innerHTML = seconds; seconds--; } }; </script>
  • 相关阅读:
    [HAOI2008]糖果传递
    [HAOI2008]木棍分割
    [HAOI2008]硬币购物
    [ZJOI2008]泡泡堂
    [JSOI2007]建筑抢修
    [JSOI2007]麻将
    [Note]prufer
    [BZOJ3275]Number
    [POI2014]RAJ-Rally
    [JSOI2010]快递服务
  • 原文地址:https://www.cnblogs.com/yuqingya/p/12196396.html
Copyright © 2011-2022 走看看