完成頁面的定時跳轉
阿新 • • 發佈:2018-01-21
ner title load doctype cte tro 百度 使用 ctype
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>
完成頁面的定時跳轉