zoukankan      html  css  js  c++  java
  • 完成页面的定时跳转

    1 使用js完成页面的定时跳转

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/jquery-2.1.0.js"></script>
            <script type="text/javascript">
                window.onload = function() {
                    var i =4;
                    var eSpan = document.getElementById("second");
                    time = setInterval(function(){
                        eSpan.innerHTML=i
                        --i;
                        if(i==0){
                            clearInterval(time);
                            location.href="http://www.baidu.com";
                        }
                    }, 1000);
                }
            </script>
    
        </head>
    
        <body>
            恭喜你注册成功<span id="second" style="color: red;">5</span>中之后跳转, 如果没有跳转点击
            <a href="http://www.baidu.com">这里</a>
        </body>
    
    </html>

    2 设置定时刷新的头

    package header;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class RefreshServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            
            //设置定时刷新的头 5秒之后跳转到百度
        response.setHeader("refresh", "5;url=http://www.baidu.com");
            
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
        }
    }

     3 使用jquery完成

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/jquery-2.1.0.js"></script>
            <script type="text/javascript">
                var time;
                var i=4; //全局变量
                $(function(){
                    time = setInterval("change()",1000);
                });
                function change(){
                    $("#second").text(i);
                    --i;
                    if(i==0){
                        clearInterval(time);
                        location.href="http://www.baidu.com";
                    }
                }
            </script>
    
        </head>
    
        <body>
            恭喜你注册成功<span id="second" style="color: red;">5</span>中之后跳转, 如果没有跳转点击
            <a href="http://www.baidu.com">这里</a>
        </body>
    
    </html>
  • 相关阅读:
    JAVA软件工程师应该具备哪些基本素质?
    java编程题(一)
    js继承之Object.create()
    【3D计算机图形学】变换矩阵、欧拉角、四元数
    JS的get和set使用示例
    深入浅析JavaScript中的constructor
    图片预加载之模拟img.load()
    threejs里面的vector3源码解析
    javascript事件轮询
    关于URL编码的一些结论
  • 原文地址:https://www.cnblogs.com/jepson6669/p/8324780.html
Copyright © 2011-2022 走看看