定时器之页面跳转

定时器之页面跳转

定时器:

只跳转一次:

var t1 = setTimeout(function a(){},time);
cleanTimeout(t1);

循环跳转多次:

var t2 = setInterval(function a(){},time);
clearInterval(t2);

js跳转:

window.location.href='${pageContext.request.contextPath}/login/first';

项目路径:

//==>localhost:8080/SSMProject
${pageContext.request.contextPath}

例子:

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/12/26 0026
  Time: 下午 3:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<title>首页</title>
<style>
h1 {
	text-align: center;
}
h4 {
	text-align: center;
	height: 100%;
	width: 100%;
}
</style>

</head>
<body>
	<h1>欢迎来到会员管理系统</h1>
	<h4 id="mes"></h4>
	<script type="text/javascript">
	var s = 6;
//  向页面添加内容
	function f1(s){
		document.getElementById("mes").innerHTML="请稍等,还有"+s+"秒跳转";
	}
	setInterval(function name(){
		s=s-1;
		f1(s);
		if(s==0){
			clearInterval();
			window.location.href='${pageContext.request.contextPath}/login/first';
		}
	}, 1000);
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_43075298/article/details/85317221